The output for this looks like this:Code:#ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include <cstdlib> using namespace std; bool yes() { string ans; while (true) { cin >> ans; if ( (ans == "Y") || (ans == "y") ) return true; if ( ans == "N" || ans == "n" ) return false; if (ans == "Q" || ans == "q" ) exit(0); cout << "Invalid option" << endl; } } int main(int argc, char *argv[]) { string file; file = "Hello, world"; cout << "Rename file to: " << file << endl; if (!yes()) getline(cin, file); cout << file; return EXIT_SUCCESS; }
Rename file to: Hello, world
n
Press Enter to continue!
For some reason it skips right over getline. Any idea of why this is happening?




Reply With Quote