Eclipse CDT 调用printf/cout 控制台(console)无输出

症状描述:

用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;
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dj0379

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值