Martin,
Your solution works fine provided that your code will run only on a Win32 system. In using this approach, however, you are sacrificing cross-platform compatibility.
While Win32 systems (and Win16 and DOS) use "\r\n" for a line separator, Unix uses only "\n" and Mac...