I know, from experience, that the following code:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
results in different line-endings being printed on different platforms (e.g. Linux: LF, Windows:CRLF) and that I sometimes have to switch count to binary mode if I want specific behaviour. Likewise I know that with filestreams I open myself I have to be careful to specify text or binary mode for my desired line-ending behaviour.
However I'm struggling to find where this behaviour of converting \n to CRLF is actually documented!
I've looked in the C++ spec (specifically C++98 through to 22) and the various online references (e.g. cppreference.com) and can't find which class / library routine is responsible for *actually converting the \n
into the platform specific line end`. (Also, don't ask ChaptGPT, it's happily making up quotes from the spec that don't exist)
Or to phrase it another way: Where is the behaviour of C++'s text-mode and binary-mode streams specified?
If it cannot be found in the C++ spec, then the question is: Is it inherited behaviour from C? If so where is that defined?
Or is this something that C just inherits from the platforms it runs on?