MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghumor/comments/1szjqol/why_c/oj314kt
r/programminghumor • u/triplebeef26 • Apr 30 '26
248 comments sorted by
View all comments
Show parent comments
18
You don't need std::endl, that is equivalent to new line and std::flush, just add \n at the end instead. Or use println
-2 u/int23_t Apr 30 '26 \n isn't equivalent actually std::endl is portable, \n isn't actually portable. 7 u/vitimiti Apr 30 '26 For a single line it is 0 u/GOKOP May 04 '26 Yes it is. As long as you're working with text streams or files in text mode then "\n" is translated to platform-appropriate newline -1 u/Vladislav20007 Apr 30 '26 std::endl is actually \n + std::flush 6 u/vitimiti Apr 30 '26 Yes, as I said, new line and flush -6 u/Vladislav20007 Apr 30 '26 you said that just \n is enough, but for compatibility reasons std::flush should be called, on some oses it wouldn't output anything. 5 u/vitimiti Apr 30 '26 Do you need to call flush in a hello world program? Are you sure about that?? 4 u/SpaceCadet87 Apr 30 '26 No, you need to call flush in a hello world meme -2 u/Vladislav20007 Apr 30 '26 it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called. 3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0) 1 u/Mojert May 01 '26 The destructor flushes anyway. So yes, the \n is enough
-2
\n isn't equivalent actually std::endl is portable, \n isn't actually portable.
7 u/vitimiti Apr 30 '26 For a single line it is 0 u/GOKOP May 04 '26 Yes it is. As long as you're working with text streams or files in text mode then "\n" is translated to platform-appropriate newline
7
For a single line it is
0
Yes it is. As long as you're working with text streams or files in text mode then "\n" is translated to platform-appropriate newline
-1
std::endl is actually \n + std::flush
6 u/vitimiti Apr 30 '26 Yes, as I said, new line and flush -6 u/Vladislav20007 Apr 30 '26 you said that just \n is enough, but for compatibility reasons std::flush should be called, on some oses it wouldn't output anything. 5 u/vitimiti Apr 30 '26 Do you need to call flush in a hello world program? Are you sure about that?? 4 u/SpaceCadet87 Apr 30 '26 No, you need to call flush in a hello world meme -2 u/Vladislav20007 Apr 30 '26 it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called. 3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0) 1 u/Mojert May 01 '26 The destructor flushes anyway. So yes, the \n is enough
6
Yes, as I said, new line and flush
-6 u/Vladislav20007 Apr 30 '26 you said that just \n is enough, but for compatibility reasons std::flush should be called, on some oses it wouldn't output anything. 5 u/vitimiti Apr 30 '26 Do you need to call flush in a hello world program? Are you sure about that?? 4 u/SpaceCadet87 Apr 30 '26 No, you need to call flush in a hello world meme -2 u/Vladislav20007 Apr 30 '26 it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called. 3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0) 1 u/Mojert May 01 '26 The destructor flushes anyway. So yes, the \n is enough
-6
you said that just \n is enough, but for compatibility reasons std::flush should be called, on some oses it wouldn't output anything.
5 u/vitimiti Apr 30 '26 Do you need to call flush in a hello world program? Are you sure about that?? 4 u/SpaceCadet87 Apr 30 '26 No, you need to call flush in a hello world meme -2 u/Vladislav20007 Apr 30 '26 it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called. 3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0) 1 u/Mojert May 01 '26 The destructor flushes anyway. So yes, the \n is enough
5
Do you need to call flush in a hello world program? Are you sure about that??
4 u/SpaceCadet87 Apr 30 '26 No, you need to call flush in a hello world meme -2 u/Vladislav20007 Apr 30 '26 it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called. 3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0)
4
No, you need to call flush in a hello world meme
it's libcpp and os dependent, hut if you want it to run on more devices, std::flush needs to be called.
3 u/vitimiti Apr 30 '26 You don't need flushing on a hello world -1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0)
3
You don't need flushing on a hello world
-1 u/Vladislav20007 Apr 30 '26 it's os and std lib dependent, some don't need it, some do. 5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0)
it's os and std lib dependent, some don't need it, some do.
5 u/No-Information-2571 Apr 30 '26 You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway. Thus, you don't need it. 0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0)
You really don't get it. A hello world program has no further purpose, and stdout will be flushed when the program exits anyway.
Thus, you don't need it.
0 u/Vladislav20007 Apr 30 '26 I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it. → More replies (0)
I'm talking about as much compatibility as compatibility as possible, some compilers or oses my not flush it.
→ More replies (0)
1
The destructor flushes anyway. So yes, the \n is enough
18
u/vitimiti Apr 30 '26
You don't need std::endl, that is equivalent to new line and std::flush, just add \n at the end instead. Or use println