If I have opened an output stream like this:
ofstream to(output_file);
How may I print new line (Looking to support different os)?
to << "\n";
to << "" <<endl;
If I have opened an output stream like this:
ofstream to(output_file);
How may I print new line (Looking to support different os)?
to << "\n";
to << "" <<endl;
End of line notation, '\n' is used in most of the systems I know except Windows (MS Dos) which use '\r\n'. What is different in between those two is that '\n' in most systems will return cursor to the beggining of new line, where in MS DOS it will go to the same character as previous line, so if you have something like this:
Hello\nWorld!!!
in most systems it will output:
Hello
World!!!
where as in MS DOS it will output:
Hello
World!!!
So to overcome this issue of different systems treating newline differently we have std::endl
, which will place correct notation for the correct system. In my code I might be bad, but I am mostly using '\n', but on the other hand I have not been using Windows as my dev machine that much.
One more point, printing out ""
is useless.