>>19
Have you read the references I left in my post?
1
Let me point you to the right direction, a simple C++ FAQ:
http://faqs.cs.uu.nl/na-dir/C++-faq/part07.html
Go and read section 15.2.
I quote:
#include <iostream>
int main()
{
std::cout << "Enter numbers separated by whitespace (use -1 to quit): ";
int i = 0;
while (i != -1) {
std::cin >> i; // BAD FORM -- See comments below
std::cout << "You entered " << i << '\n';
}
}
The problem with this code is that it lacks any checking to see if someone
entered an invalid input character.
In particular, if someone enters something that doesn't look like an integer (such as an 'x'), the stream std::cin goes into a "failed state,"
and all subsequent input attempts return immediately
without doing
anything.
In other words, the program enters an infinite loop;
if 42 was the last number that was successfully read, the program will print
the message You entered 42 over and over.
And that's why it's bad to do:
2
cin >> MyInt;
_________________________________________________________________
1This right here?
2It will also rape puppies, and your anus but honestly who
cares about
your anus.