CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    41

    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

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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.
    Last edited by John E; November 29th, 2008 at 09:31 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured