printf() does not output to the console when debugging C code

It may be troublesome to add fflush(stdout) after each printf(). You can add setbuf(stdout, NULL) before starting the program to disable the buffer, so that all output will be flushed to the console immediately. as follows:

#include <stdio.h>

int main() {
    
    
    setbuf(stdout, NULL); // 禁用缓冲区

    printf("这句话会立即输出到控制台\n");
    // ...
}

Guess you like

Origin blog.csdn.net/qq_46110497/article/details/130466008