I/O问题,为什么要endl?

netease 2000-08-09 02:18:00
为什么要endl?
cout<<"xxxxxx"<<endl
好像有时也可以不要啊!
...全文
125 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Arsoka 2000-08-17
  • 打赏
  • 举报
回复
加ENDL清空缓冲区
xubin_sh 2000-08-09
  • 打赏
  • 举报
回复
endl是换行+刷新
wai_lf 2000-08-09
  • 打赏
  • 举报
回复
endl实际上是关闭数据通道,因为,数据通道是读和写不能同时进行的,写时要加锁(防止读冲突),读时类似,这是由于读写共享数据通道造成的。也是一种安全机制。
kinghan 2000-08-09
  • 打赏
  • 举报
回复
表示整个流输出完毕。
gun2 2000-08-09
  • 打赏
  • 举报
回复
Please read this and you'll find the answer.

FROM: ostream.h/cpp

inline _CRTIMP ostream& __cdecl flush(ostream& _outs) { return _outs.flush(); }
inline _CRTIMP ostream& __cdecl endl(ostream& _outs) { return _outs << '\n' << flush; }

ostream& ostream::flush()
{
lock();
lockbuf();
if (bp->sync()==EOF)
state |= ios::failbit;
unlockbuf();
unlock();
return(*this);
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧