Below are the two lines code. Plz give a detailed explanation of these two lines

while (cin.get() != '\n')
continue;

It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff).
if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in these two lines of code.
Right solution (one of);

while (cin && cin.get() != '\n')
    continue;
// or simple
while (cin && cin.get() != '\n')
    ;

It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff).
if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in these two lines of code.
Right solution (one of);

while (cin && cin.get() != '\n')
    continue;
// or simple
while (cin && cin.get() != '\n')
    ;

The correct solution to clearing the input stream is explained here.

Hi,
I am Rammohan from Bangalore and working as a Technical lead in big IT firm .
Solution for your answer is follows:


The Syntax of the snippet code is 100% correct.
It mean that continue your while loop until the input reaches to the next line...
If you press enter key In your input stream then the loop will come out otherwise it will contnue....

Regards,
Rammohan Alampally,
<snip false signature>

I did not invent a new (incorrect) method to flush input stream.
It was a correct version of the original snippet (skip a rest of a line).

This article has been dead for over six months. Start a new discussion instead.