[C++] Exiting a program if eof condition is detected
I've got a program in which I call a recursive function that goes something like this:
myClass otherClass::foo(){
char letter;
myClass thing;
cout << "Input your letter: ";
if (cin.peek(), cin.eof()){
cout << "End of input detected.";
exit(0);
}
cin >> letter;
if (/*conditions*/){
//modify thing
return thing;
}
else
foo();
}
So it's a recursive function that keeps calling itself until the input meets the conditions, but I want it to exit the whole program if the input is .eof, the "caret and D" thing. The problem is that
if(cin.peek(), cin.eof())
Doesn't seem to detect it, because it goes right on to the next "if" statement. I've also tried this with "cin >> letter" before the .eof check, but that didn't work.
Posted Dec 2, 2012, 7:07 PM UTC · edited
2711