Thread: 0D0A character grouping?

  1. #1
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231

    0D0A character grouping?

    Hi all,

    I'm trying to read a file that is in byte format then append it onto another file. I'm doing this with unsigned char variable types because they're always one byte. Since the format is simply using bytes, they don't care about the character representation. However, when I read the characters in then put them out again, the '/n' character is always preceded by the '/r' character. In hexadecimal this looks like 0D0A. I have no control of this, and it seems as if it's being done automatically by the ofstream.put() function.

    So, is there a way to take away this appending of characters and simply writing the raw data to the file?

    Thanks.

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by xniinja View Post
    However, when I read the characters in then put them out again, the '/n' character is always preceded by the '/r' character. In hexadecimal this looks like 0D0A. I have no control of this, and it seems as if it's being done automatically by the ofstream.put() function.
    Open the file in binary mode. Text mode on Windows converts 0D0A to 0A on input and 0A to 0D0A on output.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    231
    Well, I'll be damned. That exists. Thanks for the help.

    To anyone else stumbling upon this thread, binary mode looks like this:

    Code:
    ofstream file ( "filename", ios::binary|ios::out );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grouping Question
    By baikal_m in forum C Programming
    Replies: 7
    Last Post: 10-26-2010, 04:41 PM
  2. Grouping
    By archriku in forum C Programming
    Replies: 26
    Last Post: 03-26-2009, 10:43 AM
  3. character grouping
    By imApig in forum C Programming
    Replies: 2
    Last Post: 03-20-2003, 02:22 PM
  4. Help with grouping & ignoring pronunciation
    By zipfur in forum C Programming
    Replies: 2
    Last Post: 10-17-2002, 10:29 AM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM