How to validate for a string to not contain any numerals at command prompt.
I heard of using cin.get but is not working for me.......using Turbo c++
can anybody help
read the input as you normally would (into a std::string-instance), then use std::string::find_first_not_of, passing a string with all valid characters . If the function doesn't returns std::string::npos you got something you don't want in your input.
Or you could use std::string::find_first_of to check if the string contains any "invalid" characters (which you have passed as an argument to the function).
Last edited by edoceo; 03-23-2009 at 09:42 AM.
I need that on every character entered it checks whether it's numeral or not....if not then do not accept..
> I need that on every character entered it checks whether it's numeral or not....if not then do not accept..
if you want the input to be stored inside a std::string, read my post above.
Otherwise check the returned value from std::cin to see if there was any errors while reading from that stream.
If you are trying to read data into a int/double/float/char/what/ever and the user inputs something other then what is expected (std::cin >> x) will be equal to 0.