Be careful with doing this manually.
In fact I would advise not doing this at all.
In reality we are talking about the line termination sequence LTS that is specific to platform.
If you open a file in text mode (ie not binary) then the streams will convert the "\n" into the correct LTS for your platform. Then convert the LTS back to "\n" when you read the file.
As a result if you print "\r\n" to a windows file you will get the sequence "\r\r\n" in the physical file (have a look with a hex editor).
Of course this is real pain when it comes to transferring files between platforms.
Now if you are writing to a network stream then I would do this manually (as most network protocols call this out specifically). But I would make sure the stream is not doing any interpretation (so binary mode were appropriate).