How to use is_integer in include<limit>?

Feb 11, 2010 at 11:13am
For example, I have "int x" and I want to check whether if the user has enter a integer, how to I use it like in a "if" loop or maybe other mean.
Feb 11, 2010 at 11:16am
Feb 11, 2010 at 12:33pm
thanks, but there is still one problem.
for example, I want the user to enter a medical fees and I use a program like this
"
while (true) {
cout << "Please enter a valid number: ";
getline(cin, input);

// This code converts from string to number safely.
stringstream myStream(input);
if (myStream >> myNumber)
break;
cout << "Invalid number, please try again" << endl;
}
cout << "You entered: " << myNumber << endl << endl;
"
if I enter something like "1234zzz"
the stringstream will take "1234" only.
so how can i solve this?
Feb 11, 2010 at 12:43pm
If you want to discard that kind of input, check whether myStream is empty after myStream >> myNumber
Feb 11, 2010 at 12:45pm
erm, how to check? sorry i am just starting to learn sstream.
Feb 11, 2010 at 1:14pm
You can check for myStream.eof()
Feb 15, 2010 at 12:32pm
What is myStream.eof for ?
Feb 15, 2010 at 12:44pm
To check whether the end of the stream was reached
Topic archived. No new replies allowed.