如果末尾没有 ,则 Printf 不起作用 [英] Printf not working if there isn't at the end

查看:27
本文介绍了如果末尾没有 ,则 Printf 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C 中的 printf() 函数在末尾是否需要 才能工作?

Does the printf() function in C need a at the end in order to work ?

我尝试打印出一个没有换行符的简单语句,但没有成功.

I tried printing out a simple statement without a newline at the end and it didn't work.

谢谢.

推荐答案

可能的原因是 一行缓冲 stdout,(这是定义的实现,所以我不能100%确定).在这些实现中,写入缓冲区的内容不会立即传输到输出.

The likely reason is a line buffered stdout, (this is implementation defined so I can't be 100% sure). In these implementations the content written to the buffer won't immediately be transferred to the output.

使用 " ",会导致缓冲区刷新到输出,printf 将打印内容,缺点是 " " 也会被打印出来.

Using " ", causes a flush of the buffer to the output and the printf will print the contents, the downside is that the " " will also be printed.

作为替代,您可以使用 fflush(stdout) 如果您不想打印该换行符.

As an alternative, you can use fflush(stdout) if you don't want a that newline character to be printed.

对于输出流(以及输出最后一个操作的更新流),将任何未写入的数据从流的缓冲区写入关联的输出设备.

这篇关于如果末尾没有 ,则 Printf 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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