지정된 시간 동안 공백을 허용하는 문자열 변수에 사용자의 입력을 수집하려고합니다. 보통 cin >> str
이후 std :: getline이 for 루프 내에서 작동하지 않습니다.
에서 표준 :의 getline 함께 가고 싶어 내 코드입니다 :
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++)
{
string local;
getline(cin, local); // This simply does not work. Just skipped without a reason.
//............................
}
//............................
return 0;
}
어떤 생각이?
아무 이유없이 일이 거의 실패하지 않습니다. – GManNickG
for-loop 앞에 다음을 시도하십시오. std :: cout << "n :"<< n << std :: endl; –
예. n을 올바르게 읽었습니다. n에 2를 입력하면 "n : 2"가 인쇄됩니다. –