what does this mean?

Mar 22, 2012 at 3:02pm
while(cin.get() != '\n');
What is the meaning of this?
Mar 22, 2012 at 3:21pm
cin.get() reads the next character from cin.
'\n' is the new line character
cin.get() != '\n' returns true if the read character is not a new line character
while (cin.get() != '\n'); The loop stops when it reads a character that is a new line character.

It skips the rest of the line plainly speaking. When people want to do that we often recommend doing
cin.ignore(numeric_limits<streamsize>::max(), '\n');
That will also skip the rest of the line but one important difference is that it also stops if the end of the stream is reached (cin.eof() returns true). Your loop will just continue looping infinitely.
Mar 22, 2012 at 3:30pm
what about this: while(cin.get() != '\n');
cout << endl;
Topic archived. No new replies allowed.