相关疑难解决方法(0)

std :: getline在for循环中不起作用

我正在尝试在一个字符串变量中收集用户的输入,该变量在指定的时间内接受空格.

由于通常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)

任何的想法?

c++ getline

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

getline ×1