Why is this an acceptable condition for a while loop:
But this isn't:Code:while (scanf("%d", &number) !=EOF)
Code:while ((cin >> number) !=EOF)
Why is this an acceptable condition for a while loop:
But this isn't:Code:while (scanf("%d", &number) !=EOF)
Code:while ((cin >> number) !=EOF)
My guess is because scanF is a function, and cin is an object... I don't know...
If you ever need a hug, just ask.
cin >> number will not return teh EOF on failure!!!1
.sect signature
So what would be an acceptable condition similar to the one above using cin?
I'm pretty sure there's a way to use cin and EOF in a while loop statement?
>I'm pretty sure there's a way to use cin and EOF in a while loop statement?
Yes, there is:
-PreludeCode:while ( cin>> number ) { // Loop until cin fails in any way } if ( cin.fail() ) // Error if ( cin.eof() ) // End of file etc...
My best code is written with the delete key.