Issue with C++ console output -
#include <iostream> using namespace std; int main() { cout << 1; while (true); return 0; }
i thought program should print 1 , hung. doesn't print anything, hungs. cout << endl
or cout.flush()
can solve problem, still want know why it's not working expected :) problem appeared during codeforces contest , spent lot of time on looking @ strange behavior of program. incorrect, hunged, hidden output debug information.
i tried using printf
(compiling gcc) , behaves cout
, question can referred c also.
you writing buffer. need flush buffer. @guvante mentioned, use cout.flush()
or fflush(stdout)
printf.
update:
looks fflush
works cout. don't - may not fact in cases.
Comments
Post a Comment