The first cycle getline()will loop forever unless you break it anyway. If this is done in a clean way, this should not be a problem at all. In fact, I could not reproduce your error.
How to analyze an error
, cin, Numberic non space input, . , :
cout << "Enter free lines of text or stop to return to the menu:";
while (getline(cin, line, '\n')) {
if (line == "stop")
break;
}
while (true) {
cout << "Cin status: failed="
<< cin.fail() << " bad="
<< cin.bad() << " eof=" << cin.eof() << endl;
cout << "Next char in decimal is:"
<< cin.peek() << endl;
cout << "Choose:";
cin >> choose;
cout << "selected: " << choose << endl;
}
, cin.clean(), , , (Ctrl+D Ctrl+Z ).
, peeked char (.. 48 57), , .
:
, (fail = 1, eof = 1), , . , , . pastebin , - "0", .
, (, yourprogramme <yourinput.txt) , , . , , . , cin .
, <fstream> ifstream cin .
, , (, yourprogramme yourinput.txt):
...
int main(int argc, char**argv)
{
if (argc != 2) {
cerr << "You must provide the name of the data file as command line argument\n";
return EXIT_FAILURE;
}
ifstream file(argv[1]);
if (!file) {
cerr << "Could not open "<<argv[1]<<"\n";
return EXIT_FAILURE;
}
string line;
int choose = 0;
cout << "*** Loading "<<argv[1]<< " ***" << endl;
while (getline(file, line, '\n')){
cout << "Read: " << line<<endl;
if (line == "0")
break;
}
file.close();
while (true) {
cout << "Choose (9 to exit):";
if (!(cin >> choose))
break;
cout << "selected: " << choose << endl;
if (choose == 9)
break;
}
return EXIT_SUCCESS;
}