转摘自:http://blog.csdn.net/dj0379/article/details/6940836
症状描述:
用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结尾没加
,调试时报以下错误:
!!!Hello C!!!*stopped,reason="end-stepping-range",frame={addr="0x0040140f",func="main",args=[],file="..srcHelloC.c",fullname="F:\316322265304316304265265WorkspacesHelloCDebug/..srcHelloC.c",line="24"},thread-id="1",stopped-threads="all"
加上
就好了。
int main(void) {
setbuf(stdout, NULL);
char* c="!!!Hello C!!!
";
printf(c); /* prints !!!Hello World!!! */
//fflush(stdout);
return EXIT_SUCCESS;
}