Basically you somehow managed to tell C++ to translate "\n" as 0x0A (or 0x0D only, one of those, check binary hex view if you have some handy viewer at hand).
How to fix that ... either switch the C++ compiler back to MS-DOS like line endings, or instead of "\n" use "\015\012".