症状描述:
用Eclipse调试程序,执行printf和cout函数,但是console无内容显示。
原因分析:
Eclipse输出的内容是保存在buffer中,因此要显示相关内容,就必须刷buffer缓冲区。
解决方案:
1.在main函数开始时调用函数 setbuf(stdout,NULL);
2.在每个printf函数后调用函数 fflush(stdout);
int main(void) {
setbuf(stdout, NULL); char* c="!!!Hello C!!!"; printf(c); /* prints !!!Hello World!!! */ //fflush(stdout); return EXIT_SUCCESS;}字符串c结尾没加\n,调试时报以下错误:!!!Hello C!!!*stopped,reason="end-stepping-range",frame={addr="0x0040140f",func="main",args=[],file="..\src\HelloC.c",fullname="F:\\316\322\265\304\316\304\265\265\Workspaces\HelloC\Debug/..\src\HelloC.c",line="24"},thread-id="1",stopped-threads="all"加上\n就好了。
int main(void) { setbuf(stdout, NULL); char* c="!!!Hello C!!!\n"; printf(c); /* prints !!!Hello World!!! */ //fflush(stdout); return EXIT_SUCCESS;}