Understanding Cin and Cout Order in C++

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 2K views
ineedhelpnow
Messages
649
Reaction score
0
why does cin come AFTER count and not before?
 
Physics news on Phys.org
ineedhelpnow said:
why does cin come AFTER count and not before?

If you print something with count, it is buffered before being shown.
Sometimes you need to flush count's buffer.
Either [m]flush[/m] or [m]endl[/m] will flush count's buffer so you can see it.
 
i don't understand. you can't SEE a cin statement though.

also what is a getline statement like getline (cin, s)
 
ineedhelpnow said:
i don't understand. you can't SEE a cin statement though.

Maybe I misunderstood.
What is your question? (Wondering)

also what is a getline statement like getline (cin, s)

It gets input until Enter is pressed.
The result is stored in the string s.
 
count << "whatever the heck" << usernum << " is.";
cin >> usernum

why do you do cin after count

cant you just do cin >> s?
 
ineedhelpnow said:
count << "whatever the heck" << usernum << " is.";
cin >> usernum

why do you do cin after count

cant you just do cin >> s?

It's normal to print a question before reading input.
Typically you'd do
[m]count << "Type a usernum: ";
cin >> usernum;[/m]
 
oh i see. so for the example i gave cin was not necessary?