什么是C ++ iostream endl fiasco? [英] What is the C++ iostream endl fiasco?

查看:115
本文介绍了什么是C ++ iostream endl fiasco?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在听一个 Google Talk的演讲时,Andrei Alexandrescu对D程式语言进行了讲解,内衬关于endl的失败。我只是认为endl是首选的方式来表示一行的结束和刷新缓冲区的流。为什么被认为是一个失败?

重新发布我的评论:



(我假设)他只是意味着许多,特别是新的C ++程序员使用 std :: endl 盲目而不是'\



也就是说,大多数人都被告知 std :: endl 在标准方式下将换行符插入流中,即使很少需要或适合冲洗



这是一些人的意见(*咳*), std :: endl 在标准中,因为它非常适合且不是有效的输入'\\\
'< ( s)




  • 最后, std :: endl 除了通常更糟的性能和通常更多之前没有任何东西。

  • 它有它的用途,因此...

  • 它的效用非常可疑,它的普遍性是荒谬的 - 确实是一个失败!


I was listening to a google talk by Andrei Alexandrescu on the D programming language when he threw out a one liner about the "endl" fiasco. I just thought endl was the preferred way to signify the end of a line and flush the buffer for a stream. Why is it considered a fiasco? Should I not be using it in my code?

解决方案

Reposting from my comment:

(I assume) He just means that many, especially new, C++ programmers use std::endl blindly instead of '\n' for newline, flushing unnecessarily frequently and potentially making the performance of their program abysmal.

I.e., most people are taught that std::endl is the canonical way to insert a newline into a stream even though it is very rarely necessary or appropriate to flush it.

It is some people's opinion (*cough*) that std::endl shouldn't even be in the standard, as it is so rarely appropriate and not a significant typing savings over '\n' << std::flush anyway.


TL;DR(s):

  • In the end, std::endl buys you nothing except usually worse performance and usually more typing.
  • It has its uses, but they are considerably rarer than its frequency of use in most large codebases would suggest, therefore...
  • Its utility is highly questionable and its ubiquity is absurd – a fiasco indeed!

这篇关于什么是C ++ iostream endl fiasco?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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