Binary files read newline (help)

This is a discussion on Binary files read newline (help) within the C++ Programming forums, part of the General Programming Boards category; I have a binary file which contains two numbers 1.2345 157 both number are separated with a newline. When I ...

  1. #1
    Perimeter
    Guest

    Cool Binary files read newline (help)

    I have a binary file which contains two numbers

    1.2345
    157

    both number are separated with a newline.

    When I read it back in to retieve the data I cannot get my orignal data back, I get a strange number.
    Please help.

    infile.read(buffer,4);

    while(!infile.eof())
    {

    y = (double *) &buffer[0];
    infile.read(buffer,4);
    z = *y;


    }
    unsigned int x = (unsigned int)floor(z);
    cout << z <<"|"<< x << endl;

    infile.close();

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    If that is an example of the data your binary file has, then it is not a binary file in the sense that that data is not the binary represenation of those numbers. If your numbers are seperated by a new line, why not simply do infile >> mynumber; in a loop until you hit EOF?

  3. #3
    Perimeter
    Guest

    Cool

    Sorry I meant the binary file generated contains those numbers, but when you look at the file it is garbage characters like i.e.

    @A5jdfg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-02-2008, 11:33 AM
  2. "sorting news" assignment
    By prljavibluzer in forum C Programming
    Replies: 7
    Last Post: 02-06-2008, 05:45 AM
  3. Merge Binary Files
    By chinook86 in forum C Programming
    Replies: 7
    Last Post: 01-21-2008, 01:19 PM
  4. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  5. Binary files
    By Lionmane in forum C Programming
    Replies: 35
    Last Post: 08-25-2005, 01:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21