From 9ead2c44b4bedf212aa4add84afead043110a73b Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Mon, 13 Jun 2022 18:11:50 +0200 Subject: [PATCH] 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. --- CppCoreGuidelines.md | 8 ++++++++ scripts/hunspell/isocpp.dic | 1 + 2 files changed, 9 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 0b884cc..a252c95 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -20308,6 +20308,14 @@ For writing to a file, there is rarely a need to `flush`. ##### Note +For string streams (specifically `ostringstream`), the insertion of an `endl` is entirely equivalent +to the insertion of a `'\n'` character, but also in this case, `endl` might be significantly slower. + +`endl` does *not* take care of producing a platform specific end-of-line sequence (like "\r\n" on +Windows). So for a string stream, `s << endl` just inserts a *single* character, `'\n'`. + +##### Note + Apart from the (occasionally important) issue of performance, the choice between `'\n'` and `endl` is almost completely aesthetic. diff --git a/scripts/hunspell/isocpp.dic b/scripts/hunspell/isocpp.dic index ef45e4e..e9d90e5 100644 --- a/scripts/hunspell/isocpp.dic +++ b/scripts/hunspell/isocpp.dic @@ -389,6 +389,7 @@ optimizable O'Reilly org ostream +ostringstream overabstract overconstrain overconstrained