为什么printf的输出不是通过code步进时立即显示? [英] Why does printf output not appear right away when stepping through the code?

查看:247
本文介绍了为什么printf的输出不是通过code步进时立即显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的anjuta和gdb在Fedora 20中创建一个C生成文件项目。在code是这样的:

I'm using Anjuta and gdb on Fedora 20 and created a C Makefile project. The code looks like this:

#include <stdio.h>

int main (void)
{
°   printf ("1");
°   printf ("2");
°   printf ("3");

    return (0);
}

°意味着我在那个位置设置一个断点。

° means I set a breakpoint at that position.

现在,当我调试code,没有输出,而当前行是这些的printf函数之一。只有当我退出主123出现在终端。

Now when I debug the code, there's no output while the current line is one of these printf-functions. Only when I exit main '123' appears in the terminal.

如果我\\ n添加到第二个printf的参数,那么'12',当我从断点2移动到第三个1显示为输出。

If I add \n to the second printf argument, then '12' appears as output when I move from breakpoint 2 to the 3rd one.

推荐答案

默认情况下,写一个终端,写任何其他类型的数据流时完全缓冲当标准输出行缓冲。既然你没有打印任何新行,输出被缓冲。你可以用则setbuf缓冲模式(),结束每个字符串换行符,或致电 fflush()当你要打印带PLAC。

By default, stdout is line buffered when writing to a terminal, fully buffered when writing to any other type of stream. Since you're not printing any newlines, the output is being buffered. You can change the buffering mode with setbuf(), end each string with newline, or call fflush() when you want printing to take plac.

这篇关于为什么printf的输出不是通过code步进时立即显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆