我正在尝试在一个字符串变量中收集用户的输入,该变量在指定的时间内接受空格.
由于通常cin >> str不接受空格,所以我将使用<string>中的std :: 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;
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?