cout and flushing the buffer

I'm doing an exercise with 'cout' and flushing the buffer. Upon reading in the forums, I came across this post:

Most streams by default are line buffered which means they flush any time they see a \n, so in most cases there will not be a difference.
1
2
3
4
5
int z;
cout << "Hello world";    // no \n or endl
cin >> z;                 // you won't see any output yet...
cout << "\n" << endl;    // Now you'll see Hello world
cin >> z;

..but the results were not as described above.

What actually happened was this:
1
2
3
4
5
6
7
8
int z;
cout << "Hello world";    // "Hello World" appeared here.
cin >> z;                 // Input text, pressed enter when done,
                          // cursor advanced to next line.
cout << "\n" << endl;    // No output besides cursor advancing
                         // to next line.
cin >> z;                // Receives input from what's already
                         // buffered. 


Did I misunderstand his post? Clarification would be helpful, thanks.
Generally cout and cin are tied together, so that using cin causes cout to be flushed.

http://stackoverflow.com/questions/14052627/why-do-we-need-to-tie-cin-and-cout
Topic archived. No new replies allowed.