std::getline does not work inside a for-loop

后端 未结 9 2189
醉话见心
醉话见心 2020-12-15 10:28

I\'m trying to collect user\'s input in a string variable that accepts whitespaces for a specified amount of time.

Since the usual cin >> str does

9条回答
  •  执念已碎
    2020-12-15 10:54

    My guess is that you're not reading n correctly, so it's converting as zero. Since 0 is not less that 0, the loop never executes.

    I'd add a bit of instrumentation:

    int n;
    cin >> n;
    std::cerr << "n was read as: " << n << "\n"; // <- added instrumentation
    for // ...
    

提交回复
热议问题