博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Eclipse CDT 调用printf/cout 控制台(console)无输出
阅读量:6876 次
发布时间:2019-06-26

本文共 810 字,大约阅读时间需要 2 分钟。

hot3.png

症状描述:

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

转载于:https://my.oschina.net/robslove/blog/269213

你可能感兴趣的文章
搭建nginx服务器
查看>>
java 运行 jar classpath配置
查看>>
go thrift oprot.Flush() not enough arguments in
查看>>
使用 Tomcat 7 新的连接池 —— Tomcat jdbc pool
查看>>
Spring MVC 介绍
查看>>
博客用途声明---重要
查看>>
linux .la .lo文件以及libtool介绍
查看>>
写python如何组织代码
查看>>
我的友情链接
查看>>
visual studio在浏览器中查看与运行的区别
查看>>
读书清单(2018书单)
查看>>
我的友情链接
查看>>
HTML滚动文字代码
查看>>
c#之旅--第二天
查看>>
vim复制粘贴大全
查看>>
几个Office使用中的小问题解决方法汇总
查看>>
常见硬盘加密解密的4种方法解析
查看>>
(10)MATLAB 模式识别
查看>>
OpenSSH配置文件详解
查看>>
IE浏览器中 $.ajax返回uindefined 其他浏览器正常
查看>>