문자열 출력하기

남예지·2024년 2월 7일
0

미코

목록 보기
29/37

문제

문자열 str이 주어질 때, str을 출력하는 코드를 작성해 보세요.

음. 이게 맞는지 모르겠다.

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];

rl.on('line', function (line) {
    input = [line];
}).on('close',function(){
    str = input[0];
    console.log(str)
});

흠. 이런 문제는 찐 자바스크립트 문제같아...ㅠ.ㅠ

require('readline')는 Node.js에서 사용하는 함수이다.
readline 모듈은 사용자로부터 명령줄(커맨드 라인) 입력을 받기 위해 Node.js에서 제공하는 기본 모듈 중 하나로 다른 파일이나 모듈을 현재 파일에 불러오기 위해 사용함.
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
여기서 readline.createInterface 메서드는 input 옵션으로 process.stdin을, output 옵션으로 process.stdout을 받아서 새로운 readline.Interface 인스턴스를 생성한다. 이 인스턴스인 rl을 통해 사용자로부터의 입력을 받고, 그에 대한 출력을 할 수 있습니다. 이 인스턴스를 사용해 입력에 대한 질문을 하고, 사용자의 응답을 처리하는 등의 작업을 수행할 수 있다.

node.js 문제였구나.
node공부를 하긴 해야됨...

profile
총총

0개의 댓글