Introduce this code at the beginning of main() to increase a lot the speed of cout in windows:
char buffer_setvbuf[1024];setvbuf(stdout, buffer_setvbuf, _IOFBF, sizeof buffer_setvbuf); //¿¡¡Sometimes it does not print
我在一个C项目中使用ncurses库,在初始化了printf()/puts()之后遇到了使用和去初始化的问题。下面是一个简化的例子:endwin();
usleep(1e6);first和second只在包含的可执行文件退出后才会出现在屏幕上(在超过1秒之后),而不是先打印first,然后再打印second。ncurses似乎在以某种方式缓冲stdout,只有在退出时才会刷新它。fflush(stdout)似乎解决了这个问题:endwin();
p