please help me.
I have such testing code insert in one of my sub:
I need to have a output on screen: "(i,j)=...:ratio4=...." and have a pause till I hit key.
But when I run, message 'please press any key to continue ...' appears first !!!!
and when I hit a key, other message appears including '(i,j)=...:ratio4=....'
did I missed anything ? please help
To explain why: cout is buffered by default, which means the output is only shown when the cout buffer is flushed. That happens on buffer overflow, on any input from cin, on any output to cerr, on program termination, on a call to std::flush, and on a call to std::endl, but *not* on system() call.
in your program, output was posted to cout, but not flushed (so it was not shown) when you called system("pause")
in the cin.get() solution, the call to cin.get() flushes cout and causes the output to appear
in the endl solution, the call to std::endl() does the same