“endl和”\ n“ [英] "endl and "\n"

查看:64
本文介绍了“endl和”\ n“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于代码,outputfile<< * p<<结束;


有人建议:不要在这里使用endl;它是每个

时间刷新输出流。使用简单的''\ n''。


使用endl的区别是什么?和\ n以上?

刷新输出流的含义是什么?这不是我们想要的吗?


谢谢!

For the code, outputfile << *p << endl;

Someone suggests: Don''t use endl here; it is flushing output stream every
time. Use plain ''\n''.

What''s the difference of using "endl" and "\n" above? What''s the meaning of
flushing output stream? Isn''t that what we want?

Thanks!

推荐答案



" dover" <做***** @ close.com>在消息中写道

新闻:M%******************** @ bgtnsc04-news.ops.worldnet.att.net ...

"dover" <do*****@close.com> wrote in message
news:M%********************@bgtnsc04-news.ops.worldnet.att.net...
对于代码,outputfile<< * p<< endl;

有人建议:不要在这里使用endl;它是每个时间刷新输出流。使用简单的''\ n''。

使用endl的区别是什么?和\ n以上?刷新输出流的
是什么意思?这不是我们想要的吗?
For the code, outputfile << *p << endl;

Someone suggests: Don''t use endl here; it is flushing output stream every
time. Use plain ''\n''.

What''s the difference of using "endl" and "\n" above? What''s the meaning of flushing output stream? Isn''t that what we want?




有人已经给你答案;-),它正在刷新输出流

每个时间。在这里缓冲意味着你写入

流的所有内容都不会转到外部设备,而是IOStreams正在缓冲(存储)

它在某些时候它们将它刷新到外部设备。这提高了

的效率。每一个endl你冲洗流可能是一种矫枉过正。


-Sharad



Somebody had already given you the answer ;-), it is flushing output stream
every time. Buffering here means that not everything that you write into the
stream goes to the external device, instead IOStreams is buffering (storing)
it and at some point they flush it to the external device. This boosts the
efficiency. With every endl you flush the stream which may be an overkill.

-Sharad


dover写道:

对于代码,outputfile<< * p<< endl;

有人建议:不要在这里使用endl;它是每个时间刷新输出流。使用简单的''\ n''。

使用endl的区别是什么?和\ n以上?
刷新输出流的含义是什么?这不是我们想要的吗?

For the code, outputfile << *p << endl;

Someone suggests: Don''t use endl here; it is flushing output stream every
time. Use plain ''\n''.

What''s the difference of using "endl" and "\n" above? What''s the meaning of
flushing output stream? Isn''t that what we want?




重点是:

大多数操作系统或大多数C ++库都做一种缓冲。

如果你做输出,输出不会立即发送到

输出设备,而是缓冲到特定数量的

收集缓冲的输出,然后将其一个块发送到

设备。这样做的原因仅仅是效率。要将一些

数据传递到接收设备,数据必须通过C ++库和/或操作系统中的各个阶段

。所有这些都花费了b / b $ b时间,例如,这样做会浪费时间。每个单独的

字符。


但有时你想要的是:没有缓冲,每个角色都被发送

立即到设备一旦可用。这是情况

,其中冲洗发挥作用。无论缓冲策略如何,都要求清空所有缓冲区

并将数据发送到设备。

示例:如果通过插入输出调试旧方法声明进入

您的源代码并观察您在崩溃前最后看到的那个。这里

你不需要一些缓冲来掩盖输出流。


-

Karl Heinz Buchegger
kb******@gascad.at


Karl Heinz Buchegger< kb ****** @ gascad.at>在消息新闻中写道:< 40 *************** @ gascad.at> ...
Karl Heinz Buchegger <kb******@gascad.at> wrote in message news:<40***************@gascad.at>...
dover写道:

对于代码,outputfile<< * p<< endl;

有人建议:不要在这里使用endl;它是每个时间刷新输出流。使用简单的''\ n''。

使用endl的区别是什么?和\ n以上?
刷新输出流的含义是什么?这不是我们想要的吗?

For the code, outputfile << *p << endl;

Someone suggests: Don''t use endl here; it is flushing output stream every
time. Use plain ''\n''.

What''s the difference of using "endl" and "\n" above? What''s the meaning of
flushing output stream? Isn''t that what we want?



关键是:
大多数操作系统或大多数C ++库都做一种缓冲。
如果你这样做输出时,输出不会立即发送到输出设备,而是缓冲直到收集到特定数量的缓冲输出,然后将其一个块发送到
设备。这样做的原因仅仅是效率。要将一些数据传递到接收设备,数据必须通过C ++库和/或操作系统中的各个阶段。所有这些都需要时间,例如,这样做会浪费时间。每个单独的角色。

但有时你想要的是:没有缓冲,每个角色一旦可用就会立即发送给设备。这就是冲洗发挥作用的情况。无论缓冲策略如何,都要求清空所有缓冲区并将数据发送到设备。
示例:如果通过将输出语句插入到源代码中来调试旧方法代码并观察您在崩溃前最后看到的那个。这里
你不想要一些缓冲来掩盖输出流。



The point is:
Most operating systems or most C++ libraries do a sort of buffering.
If you do an output, the output is not immediatly sent to the
output device, but instead is buffered until a specific amount of
buffered output is collected, which is then sent in one chunk to the
device. The reason why this is done is simply efficiency. To hand some
data through to the receiving device, the data has to pass various stages
in either the C++ library and/or the operating system. All of them take
time and it would be a waste of time to do that for eg. each single
character.

But sometimes you want exactly that: no buffering, each character is sent
immediatly to the device as soon as it is available. This is the situation
where flushing comes into play. It is the request to empty all those buffers
and sent the data to the device, regardless of buffering strategy.
Example: If you do debugging the old way by inserting output statements into
your source code and watching which one you saw last before the crash. Here
you don''t want some buffering to occour and thus you flush the output stream.




是的,我们都知道这一点,但令我惊讶的是大多数教科书

作者几乎都不会使用\ n,他们只是继续使用std :: endl,

而不强调效率的潜在损失。


-

Imanpreet Singh Arora为了画画需要6件事:

ikaur #AT#acm#DOT#org spirit,rhythm,thought,scenery,pen

and ink"

mv kaur singh



Yes, we all know this but what surprises me is that most of textbook
authors pretty much NEVER use "\n", they just keep on using std::endl,
without highlighting the potential loss in efficiency.

--
Imanpreet Singh Arora "In order to paint 6 things are required:
i"kaur" #AT# acm #DOT# org spirit, rhythm, thought, scenery, pen
and ink"
mv kaur singh

这篇关于“endl和”\ n“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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