|It's just not that simple. A file is essentially an array of bytes on disc, which are written sequentially. There is no structure or other information, such as start of line, or record size or anything like that associated with a file(1). When you write a Carriage Return ('\r' hex 0D) to the file, it just appends a CR character at the current location in the file.
Exactly what you need to do, depends on what your exercise is.
If you've got a single string of text as shown above, you'll need to examine each character and decide what to do when you find either a '\n' (start a new line) or a '\r' (move to the beginning of the current line). When you find a newline character, you'll need to write that to the file, and use
tellp() to record the current location. When you find a CR ('\r') you'll want to then use
seekp() to move to the location returned by the previous
tellp(). Don't forget to initialize the variable you use for the result of
tellp() when you open the file.
If, on the other hand, you have pairs of input, e.g an initial string ("This is some text") and then the text to overwrite ("Overwrite") then its a bit simpler. You still need to record your current location in the file, but you won't need to examine each character for a CR or NL. You just need to record where you are in the file before you write the line, then use
seekp() to move back there when you get the next line of input.
In both cases, you may need to think about what happens when you have multiple lines of input. Are you expected to then move to then end of the current line and continue on, or continue writing at the current file cursor location.
If you know you will only have a single line of text, followed by a single line to overwrite with, things are simpler still. In this case, you just need to write the first line of text, then
seekp(0) to the beginning of the file, and write the second line of text.
(1) This might not be true for all OS's out there. But if you're using Windows, Linux or OS-X, then that is the case.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown