>if (value < o)
You may need to change your font. The letter o is not the same as the integer 0.
>Hopefully later this evening.
Okay, a stream is basically just a bunch of characters in sequence. For example:
atest
When you open the stream, you can see 'a'. However, to get to any of the other characters on the stream, you have to extract all of the characters in front of them. So to get to 's', we would have to extract 'a', 't', and 'e'. A stream is filled with characters from an outside source such as the keyboard.
When it comes to basic input in C++, you need to remember only two things:
1) Input in C++ is line oriented
2) Anything that doesn't read an entire line may leave characters on the stream
By "reading an entire line", I mean reading all characters up to and including the '\n' character, which signals the end of a line. Two common ways of getting input willnot read an entire line. The first way is single character input with cin.get():
cout<< cin.get() <<endl;
If the user types "atest" then cout will print 'a', and "test" will be left on the stream. A subsequent call to cin.get() will immediately read 't' instead of waiting for more input, as it would if the stream were empty.
The second way is any input using cin's >> operator. Think about it, if the stream contained "12345atest" and you told cin to take an integer:
int x;
cin>> x;
Then it will stop at the first non-integer character, which would be 'a'. Therefore, "atest" would be left on the stream.
Now, an input stream defines the ignore() member function that basically reads characters from the stream and discards them until a limit is reached, either by reading N characters, or reading a certain character:
void ignore ( int n, char delim = EOF )
{
char ch;
while ( --n >= 0 && ( ch = get() ) != delim )
;
}
So let's look at the first solution:
cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
numeric_limits is a template that defines a max() function. The max() function returns the total number of characters a stream can hold. So ignore will read at least as many characters as a full stream has. The second argument defines the newline character as a delimiter, so ignore will read at least as many characters as a full stream has, or until a newline character is read. Remember, because input in C++ isline oriented, this effectively discards all of the characters in the stream because there is unlikely to be characters beyond a newline on an interactive stream like cin.
That's the simplest of the solutions to understand. The second is:
cin.ignore ( cin.rdbuf()->in_avail() );
Every stream has a buffer for efficiency reasons, and in C++ that buffer knows how many characters it has. Put simply, the stream knows how many characters are on the stream. You can find out that tidbit of information by calling the in_avail() member function of the stream buffer, which can be obtained by calling the rdbuf() member function of the stream.
Because the second argument to ignore has a default value, you can omit it in the function call and it will default to the end-of-file. The call basically says to discard all existing characters on the stream.
The third solution is the shortest, but also the most difficult to understand:
cin.sync();
Without getting into the nitty-gritty details of the C++ Standard language, and reasons why this solution is debatable (though I have yet to see it fail to work properly), sync will remove all characters from the stream.