std::getline on std::cin

Most likely you are trying to read a string after reading some other data, say an int. consider the input: 11 is a prime if you use the following code: std::cin>>number; std::getline(std::cin,input) the getline will only read the newline after 11 and hence you will get the impression that it’s not waiting for user input. … Read more

checking for eof in string::getline

The canonical reading loop in C++ is: while (getline(cin, str)) { } if (cin.bad()) { // IO error } else if (!cin.eof()) { // format error (not possible with getline but possible with operator>>) } else { // format error (not possible with getline but possible with operator>>) // or end of file (can’t make … Read more