[LC++]IO in C++

Jack Lloyd lloyd at acm.jhu.edu
Wed Nov 14 03:51:26 UTC 2001


Not necesarily better, but my usual strategy when I don't trust the user to
do it right is read the entire line as a std::string, then parse and decode
it myself, calling is*() as needed to verify the characters are valid. -J

> The best I have been able to come up with is:
>
> istringstream iss(myString); char tempChar;
> if (!(iss>>verbosity)||(iss>>tempChar))
>   cout<<"Error: myString is not an integer\n";
>
> Better solutions are welcome :-)




More information about the tuxCPProgramming mailing list