MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/aupw3q/dont_use_stdendl/ehb1hea/?context=3
r/cpp • u/vormestrand • Feb 25 '19
52 comments sorted by
View all comments
98
std::endl is a fine convention for interactive console i/o.
std::endl
In particular it helps ensure that all relevant output has been presented when a program crashes.
Not using endl and so misinterpreting what the output says about where the crash occurred, is a common beginner's problem.
endl
endl is not fine for efficient text file i/o, but then iostreams are not fine for that in the first place.
So, the advice to ditch endl is ill-conceived, in both mentioned cases, and I can't think of more.
9 u/VirtueBot Feb 25 '19 I didn't think the author was trying to deny any use cases for flushing the stream, just that std::flush should be used instead of endl in those case. 5 u/jcelerier ossia score Feb 26 '19 The mere thought of typing << '\n' << std::flush; makes me want to slice my wrists 7 u/anders1234 C++ since MSC 6.0 Feb 26 '19 It seems more readable (at least for me) writingstd::cout << "hello world" << std::endl;thanstd::cout << "hello world\n" << std::flush;but maybe I am just a n00b. 2 u/VirtueBot Feb 26 '19 oooooo this talk of slicing wrists is making me hot for std::flush!fwiw I would write endl in that case too lol. But if it's "text\n" << std:: flush that sounds more appealing to me after reading the article.Otoh maybe take a break before the next time you write to the console (;
9
I didn't think the author was trying to deny any use cases for flushing the stream, just that std::flush should be used instead of endl in those case.
5 u/jcelerier ossia score Feb 26 '19 The mere thought of typing << '\n' << std::flush; makes me want to slice my wrists 7 u/anders1234 C++ since MSC 6.0 Feb 26 '19 It seems more readable (at least for me) writingstd::cout << "hello world" << std::endl;thanstd::cout << "hello world\n" << std::flush;but maybe I am just a n00b. 2 u/VirtueBot Feb 26 '19 oooooo this talk of slicing wrists is making me hot for std::flush!fwiw I would write endl in that case too lol. But if it's "text\n" << std:: flush that sounds more appealing to me after reading the article.Otoh maybe take a break before the next time you write to the console (;
5
The mere thought of typing << '\n' << std::flush; makes me want to slice my wrists
<< '\n' << std::flush;
7 u/anders1234 C++ since MSC 6.0 Feb 26 '19 It seems more readable (at least for me) writingstd::cout << "hello world" << std::endl;thanstd::cout << "hello world\n" << std::flush;but maybe I am just a n00b. 2 u/VirtueBot Feb 26 '19 oooooo this talk of slicing wrists is making me hot for std::flush!fwiw I would write endl in that case too lol. But if it's "text\n" << std:: flush that sounds more appealing to me after reading the article.Otoh maybe take a break before the next time you write to the console (;
7
It seems more readable (at least for me) writingstd::cout << "hello world" << std::endl;
std::cout << "hello world" << std::endl;
than
std::cout << "hello world\n" << std::flush;
but maybe I am just a n00b.
2
oooooo this talk of slicing wrists is making me hot for std::flush!
fwiw I would write endl in that case too lol. But if it's "text\n" << std:: flush that sounds more appealing to me after reading the article.
Otoh maybe take a break before the next time you write to the console (;
98
u/alfps Feb 25 '19
std::endlis a fine convention for interactive console i/o.In particular it helps ensure that all relevant output has been presented when a program crashes.
Not using
endland so misinterpreting what the output says about where the crash occurred, is a common beginner's problem.endlis not fine for efficient text file i/o, but then iostreams are not fine for that in the first place.So, the advice to ditch
endlis ill-conceived, in both mentioned cases, and I can't think of more.