癥狀描述:
用Eclipse調(diào)試程序,執(zhí)行printf和cout函數(shù),但是console無內(nèi)容顯示。
原因分析:
Eclipse輸出的內(nèi)容是保存在buffer中,因此要顯示相關(guān)內(nèi)容,就必須刷huffer緩沖區(qū)。
解決方案:
1.在main函數(shù)開始時(shí)調(diào)用函數(shù) setbuf(stdout,NULL);
2.在每個(gè)printf函數(shù)后調(diào)用函數(shù) fflush(stdout);
int main(void) {
setbuf(stdout, NULL);
char* c="!!!Hello C!!!";
printf(c); /* prints !!!Hello World!!! */
//fflush(stdout);
return EXIT_SUCCESS;
}
字符串c結(jié)尾沒加\n,調(diào)試時(shí)報(bào)以下錯(cuò)誤:
!!!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;
}
聯(lián)系客服