My environment is Debian GNU/Linux 11.
The fprintf
function with param stdout
or stderr
gives unexpected output order.
int main() {
std::cout << "Hello, World!" << std::endl;
fprintf(stderr, "22222\n");
fprintf(stdout, "111\n");
printf("3333 \n");
printf("44444 \n");
return 0;
}
I've run this many times and got many different results:
//①
22222
Hello, World!
111
3333
44444
//②
Hello, World!
111
3333
44444
22222
What's the reason? Or, I want to understand the phenomenon, what knowledge do I need?
On my understanding, the output log should like this:
//③
Hello, World!
22222
111
3333
44444
About the two output logs of ①/②, I don't understand.
I think log ③ is right, but it does not appear, that makes me wonder.