Warp wrote:
> The above example code can thus be written as:
>
> while(true)
> {
> int value;
> std::cin >> value; // Try to read an integer
> if(std::cin.fail()) // If there was no integer in the input
> {
> std::cin.clear(); // Clear the error flags
> std::string s;
> std::cin >> s; // Read a string
> if(!std::cin.good()) break;
> std::cout << "The input was something else: " << s << "\n";
> }
> else
> {
> std::cout << "The input was an integer: " << value << "\n";
> }
> }
>
> Thus removing the need for stringstreams.
This doesn't appear to work. It waits for me to type a second token, and
then works with that. (Either that or my program has some other random
bug... If I ever figure out how to work VisualStudio's debugger I'll let
you know!)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|