Skip to content

Commit 9ead2c4

Browse files
authored
SL.io.50 (Avoid endl): Mention string streams (#1920)
Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov.
1 parent a534f4a commit 9ead2c4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CppCoreGuidelines.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20308,6 +20308,14 @@ For writing to a file, there is rarely a need to `flush`.
2030820308

2030920309
##### Note
2031020310

20311+
For string streams (specifically `ostringstream`), the insertion of an `endl` is entirely equivalent
20312+
to the insertion of a `'\n'` character, but also in this case, `endl` might be significantly slower.
20313+
20314+
`endl` does *not* take care of producing a platform specific end-of-line sequence (like "\r\n" on
20315+
Windows). So for a string stream, `s << endl` just inserts a *single* character, `'\n'`.
20316+
20317+
##### Note
20318+
2031120319
Apart from the (occasionally important) issue of performance,
2031220320
the choice between `'\n'` and `endl` is almost completely aesthetic.
2031320321

scripts/hunspell/isocpp.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ optimizable
389389
O'Reilly
390390
org
391391
ostream
392+
ostringstream
392393
overabstract
393394
overconstrain
394395
overconstrained

0 commit comments

Comments
 (0)