{"action":"created","issue":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/357","labels_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/357/labels{/name}","comments_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/357/comments","events_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/357/events","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/357","id":113157421,"number":357,"title":"Proposal to outlaw std::endl","user":{"login":"Florianjw","id":554592,"avatar_url":"https://avatars.githubusercontent.com/u/554592?v=3","gravatar_id":"","url":"https://api.github.com/users/Florianjw","html_url":"https://github.com/Florianjw","followers_url":"https://api.github.com/users/Florianjw/followers","following_url":"https://api.github.com/users/Florianjw/following{/other_user}","gists_url":"https://api.github.com/users/Florianjw/gists{/gist_id}","starred_url":"https://api.github.com/users/Florianjw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Florianjw/subscriptions","organizations_url":"https://api.github.com/users/Florianjw/orgs","repos_url":"https://api.github.com/users/Florianjw/repos","events_url":"https://api.github.com/users/Florianjw/events{/privacy}","received_events_url":"https://api.github.com/users/Florianjw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-10-24T12:32:08Z","updated_at":"2015-10-26T03:19:39Z","closed_at":null,"body":"Writing a `std::endl` to a stream is exactly equivalent to writing a `'\\n'`, followed by a `std::flush` to a stream. In my experience very few people are unaware of the later part and for some reason assume that it is instead a portable way to print a newline (which it technically is, but so is `'\\n'`). Many of them are surprised, sometimes shocked, when they learn the truth, because they excessively use it in their codebase whenever they need a newline, thereby slowing down everything for no gain at all. (This is premature pessimization!)\r\n\r\nEven for people who are aware of the truth this can be a disadvantage because they have to find out whether the flush is really necessary in the particular place, or whether they can replace multiple writes with one.\r\n\r\nThe following is similar to what I've seen in the wild:\r\n\r\n```cpp\r\nstd::cout << \"foo\" << std::endl\r\n          << \"bar\" << std::endl << std::endl\r\n          << \"baz\" << std::endl;\r\n```\r\n\r\nThis can be replaced with\r\n\r\n```cpp\r\nstd::cout << \"foo\\n\"\r\n             \"bar\\n\\n\"\r\n             \"baz\\n\";\r\n```\r\n\r\nWhich is just one write-call and additionally improves readability by reducing line-noise (this is even more true in editors that highlight escape-sequences).\r\n\r\nFor the few cases where flushing is really desired, `std::flush` works perfectly well and actually states the intent:\r\n\r\n```cpp\r\nstd::cout << \"Some log-statement\\n\" << std::flush;\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/comments/151012249","html_url":"https://github.com/isocpp/CppCoreGuidelines/issues/357#issuecomment-151012249","issue_url":"https://api.github.com/repos/isocpp/CppCoreGuidelines/issues/357","id":151012249,"user":{"login":"RicoAntonioFelix","id":6290785,"avatar_url":"https://avatars.githubusercontent.com/u/6290785?v=3","gravatar_id":"","url":"https://api.github.com/users/RicoAntonioFelix","html_url":"https://github.com/RicoAntonioFelix","followers_url":"https://api.github.com/users/RicoAntonioFelix/followers","following_url":"https://api.github.com/users/RicoAntonioFelix/following{/other_user}","gists_url":"https://api.github.com/users/RicoAntonioFelix/gists{/gist_id}","starred_url":"https://api.github.com/users/RicoAntonioFelix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RicoAntonioFelix/subscriptions","organizations_url":"https://api.github.com/users/RicoAntonioFelix/orgs","repos_url":"https://api.github.com/users/RicoAntonioFelix/repos","events_url":"https://api.github.com/users/RicoAntonioFelix/events{/privacy}","received_events_url":"https://api.github.com/users/RicoAntonioFelix/received_events","type":"User","site_admin":false},"created_at":"2015-10-26T03:19:39Z","updated_at":"2015-10-26T03:19:39Z","body":"`std::cout` is an object of the specialization `std::ostream` therefore std::endl relates to both..."}}