I have an application that is waiting on input from the user to issue a command, when it receives the command, a large amount is printed to the screen. The app crashes when looping around waiting on std::getline
the second time. I think this is because the buffer is full or something. If I hardcode the string rather than reading from std::cin
there is no crash. How can I flush the buffer before reading the second time, I used the following but it doesn't work std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
#include <iostream>
#include <string>
int main ()
{
while(true){
std::string input{};
// if string is hardcoded app works so issue is with std::cin
// std::string input{"command_one"};
if (!std::getline(std::cin, input))
{
continue;
}
// app does work and prints alot to screen
}
}