C++에서는 getline() 함수를 사용하여 스트림에서 줄을 읽습니다. Enter 버튼을 누르거나 사용자가 지정한 구분 기호가 제공될 때까지 입력을 받습니다. 여기에서는 getline() 함수를 사용하여 줄 바꿈 문자를 입력으로 사용하는 방법을 볼 것입니다. 아이디어를 얻기 위해 다음 구현을 살펴보겠습니다.
예시
#include<iostream>
using namespace std;
int main() {
string str;
int term = 4;
while (term--) {
getline(cin, str);
while (str.length()==0 )
getline(cin, str);
cout << str << " : New Line" << endl;
}
} 출력
Hello Hello : New Line World World : New Line This is This is : New Line C++ Language C++ Language : New Line