注册 登录
编程论坛 C++教室

求助:C++中endl和\n的区别

Krift 发布于 2012-11-22 21:22, 1720 次点击
本人新手菜鸟一枚,最近刚入门C++、、

之前看到就在本论坛看到网友说endl=\n+flush,\n只是换行并不清空缓冲区,但是在谭浩强的C++程序设计中说的(划线部分),貌似\n也清空缓冲区???
只有本站会员才能查看附件,请 登录


这该怎么理解啊?


13 回复
#2
qunxingw2012-11-22 21:41
如果不搞研究就先背下
#3
mw11592166452012-11-23 09:14
endl表示换行    \n 相当于空格
#4
rjsp2012-11-23 09:34
endl=\n+flush 肯定是没错的,因为C++标准中就是这些写的
ISO/IEC 14882:2003(E)第27.6.2.7章节:
namespace std {
  template <class charT, class traits>
    basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>&os);
}
Effects: Callsos.put(os.widen('\n') ), then os.flush().
Returns: os.
The effect of executingcout << endl is to insert a newline character in the output sequence controlled by cout, then synchronize it with any external file with which it might be associated.

#5
mmmmmmmmmmmm2012-11-23 10:34
请问版主  这个标准在那里有 我也想看看



之前只知道 ends endl 和flush 学习一下 还有'\n'

以下是引用rjsp在2012-11-23 09:34:19的发言:

endl=\n+flush 肯定是没错的,因为C++标准中就是这些写的
ISO/IEC 14882:2003(E)第27.6.2.7章节:
namespace std {
  template <class charT, class traits>
    basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>&os);
}
Effects: Callsos.put(os.widen('\n') ), then os.flush().
Returns: os.
The effect of executingcout << endl is to insert a newline character in the output sequence controlled by cout, then synchronize it with any external file with which it might be associated.
#6
rjsp2012-11-23 12:00
回复 5楼 mmmmmmmmmmmm
ISO/IEC 14882:2003(E) 就是 ISO C++ 2003 修订版,你自己在网上google吧
最新的 ISO C++ 2011 版网上也有,但不知道真假
#7
天剑山2012-11-24 14:22
...\n 会新缓冲区?不是吧?应该不能够的,C++Primer貌似说过不行的....
#8
Krift2012-11-25 23:30
回复 3楼 mw1159216645
不是吧、、、你搞错了。。
#9
lz10919149992012-11-25 23:45
endl输出一个换行(\n)然后刷新缓冲区。
\n只在C里会刷新缓冲区,C++里不会。
#10
mfkblue2012-11-26 01:43
9楼这个老头的头像,我在另个论坛也看到过,不知道是不是同一个人,发了一个看起超牛的贴子,好像是硬件驱动,C++编程图像啥的,反正看不懂,只觉得牛X。
LZ有潜力,我一般能跳过就跳过,不能跳过的也跳过,哪里会想的这么仔细。

[ 本帖最后由 mfkblue 于 2012-11-26 01:45 编辑 ]
#11
lz10919149992012-11-26 08:58
回复 10楼 mfkblue
你不知道他是谁吗?C++之父罢。那个论坛的肯定不是我,我还只是个新手。
#12
rjsp2012-11-26 09:11
回复 10楼 mfkblue
^_^ 那人叫 Bjarne Stroustrup,就是C++这个语言的发明人
他的主页地址: http://www.
#13
wj133703362012-11-26 14:36
endl在C++中用的频繁!\n在c语言中经常用!
#14
浏览浏览嘎嘎2012-11-26 15:04
回复 楼主 Krift
大哥,你有可以在win7 32位操作系统上运行的 C++么???急求。。有的话发我邮箱,997492695@谢谢。
1