I am a beginning programmer, and am trying to work with exception handling in C++. I found a method for validating input that seems pretty versatile, but I want to add an exception that will end the program if a user enters Ctrl-z.
Here is the function I found:
cout << "Please enter a decimal value:" << endl;
while ((cin >> number).fail() || number < 0 || cin.peek() != '\n'){
cin.clear();
while (cin.get() != '\n'){ continue; cin >> number; } cout << "Invalid Input" << endl;
I am working on a problem with vectors. I know that Ctrl-z sends an empty string; I'm wondering if there is a way to incorporate a condition that breaks from here if number is equal to Ctrl-z?
I hope that this question is clear enough.