[LC++]IO in C++

Mark Phillips mark at austrics.com.au
Tue Nov 13 16:36:04 UTC 2001


Mark Phillips wrote:
> 
> > > int myInt;
> > > string myString="259";
> > > istringstream iss(myString);
> > > iss>>myInt;
> 
> What if we want to do error checking on myString?
> 

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