Using cin with while

Can anyone please explain the following code ?

1
2
3
4
char buffer[10]; //declares a char array of length 10
while(cin >> buffer){ //?
 cout << buffer ; //prints the buffer on standard output
}
Edit; heh
Last edited on


while(cin >> buffer){

}

cin >> buffer is a statement. While loops can take either statements or conditionals. A statement always evaluates to true. So what is happening is the while loop keeps running the statement, which evaluates to true, and you end up with an infinite loop.

If you want a useful answer some more context would be helpful. Where did you get the code form?
Initially ,I thought some kind of comparison is taking place.
But here, it means that the statement cin >> buffer will always evaluate to true .
That means for compiler code above is equivalent to
1
2
3
4
while(true){
  cin >> buffer ;
  cout << buffer ;
}

Thanks for replying , the question was too basic
Topic archived. No new replies allowed.