What does it mean to write to stdout in C?

后端 未结 6 1297
慢半拍i
慢半拍i 2020-12-13 23:35

Does a program that writes to \"stdout\" write to a file? the screen? I don\'t understand what it means to write to stdout.

6条回答
  •  猫巷女王i
    2020-12-14 00:31

    @K Scott Piel wrote a great answer here, but I want to add one important point.

    Note that the stdout stream is usually line-buffered, so to ensure the output is actually printed and not just left sitting in the buffer waiting to be written you must flush the buffer by either ending your printf statement with a \n

    Ex:

    printf("hello world\n");
    

    or

    printf("hello world"); 
    printf("\n");
    

    or similar, OR you must call fflush(stdout); after your printf call.

    Ex:

    printf("hello world"); 
    fflush(stdout);
    

    Read more here: Why does printf not flush after the call unless a newline is in the format string?

提交回复
热议问题