system("PAUSE") Problem.....

Ok, here's the situation....I have this code...

#include <iostream.h>
#include <stdlib.h>

int main()
{
cout << "\nBlah, and Blah\n\n";

           system\("PAUSE"\);

           return 0;

}

Now, "system("PAUSE")" gets executed before "cout" does, and I have absolutely no idea why, so when I type this in instead...

#include <stdio.h>
#include <stdlib.h>

int main()
{
printf ("\nBlah, and Blah\n\n");

system\("PAUSE"\);

return 0;

}

...it works just fine....it's like printf has precidence over cout, which I need to fix. So, does anyone know another way for a PAUSE using cout, and does anyone have anymore information on why this situation occurs? Thanks!

Mike

Any output to stdout/cout is buffered (unless you have set the
proper ioctl's for unbuffered output) so there is no
guarantee that you will see the output when the
cout << ... OR printf() is executed. If you want to guarantee
that the output goes to the screen prior to executing the
next statement, in C++ you can simply add " << endl" or
in C you can call fflush(stdout) prior to calling "system()".

Actually, the fact the printf() works is hit or miss.
It may or may not work.

This answered my question _perfectly_, :slight_smile: thank you very much for your help, i appreciate it

Mike