Problem solved, thanks.

Started by
0 comments, last by Trap 17 years, 9 months ago
Trap had the solution. Thanks very much for the prompt reply! Hello. I'm working on a checkers program, and I'm having a bit of a problem.. I'm using the console to draw the board each frame.. But for some reason, cout isn't printing to the screen when I tell it to! It seems as if it fills up its buffer, and then dumps everything to the screen at once. Look at this loop, here. while(true){ system("pause"); cout<<"This is a test\n"; } Simple, right? It should display "Press any key to continue", and then when you press a key, it should display "This is a test" and start over. Right? Nope! You have to press a key about 35 times, and then it will dump all of the stored "This is a test" lines to the screen. It even splits the output! You get something like This is a test This is a test This is a test This is a tPress any key to continue . . . <- notice this line.. Press any key to continue . . . I can also confirm that this is not caused by the system("pause"). If I use Sleep(100) instead, it waits about 3 seconds, displays 35 lines of "This is a test", waits another 3 seconds, displays 35 more lines, etc. Any clue how to print to the console without this strange delay? Thanks much for your help, Adam
Advertisement
cout.flush();
or
use cout << std::endl; which outputs '\n' and flushes the output afterwards
or
use cin.get() instead of system("pause"), reading from cin automatically flushes cout.

This topic is closed to new replies.

Advertisement