Writing UNIX compatible carriage returns
Hi all
I am writing a simple Windows MFC program which generates an input file for a program which we have installed under Linux. At the moment, when I try to run the program under Linux on this input file, I need to first use the "dos2unix" utility to convert all dos carriage returns to linux/unix since otherwise the Linux Program fails to run. The code I use in the Windows MFC program to write the input files for the Linux program is something like:
outf << " PCH 2 2 2\r\n";
What should I be using instead of "\r\n" to write a Linux/Unix compatible carriage return.
Thanks for reading,
Robbie
Re: Writing UNIX compatible carriage returns
Your problem is caused by the fact that your file is a text file. Try creating the file as a binary file and using
outf << " PCH 2 2 2\n";
or
outf << " PCH 2 2 2" << endl; is safer (because it flushes the buffer) and will hopefully work too (but the file must be binary). This behaviour is automatic for Windows when writing to a text file. I don't think there's anything you can do apart from creating a binary mode file.