Please see my comments to the question. You did not even try to insert or add a new line.
C++ "object-oriented" << stream operators are so inconvenient! But perhaps you have to learn how to work with them. In this style of stream programming, there is and
endl
manipulator:
endl — C++ Reference[
^].
Alternatively, you can simply use "\n" inside one of your strings, as shown here:
Basic Input/Output - C++ Tutorials[
^].
Now, there is one extremely unpleasant problem: the line separators used in files and strings are platform-dependent. This article provides a pretty comprehensive overview of the problem:
Newline — Wikipedia, the free encyclopedia[
^].
There are programming systems providing multiplatform facility for using this separator, that's it, they return different strings on different OS, and then you add/return this string, which is not statically defined in your code. For C++, such approach is not typical: if you write "\n", this is always a character with code point 10, and "\r" — 13, that's it.
From the other hand, more and more software products are developed to be tolerant to the kinds of line separator, they "normalize" the. Say, if you read the file as is and feed resulting string to a Windows
MessageBox
, the message would be shown the same way, even if you use a line separator from some other OS.
—SA