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

    How do I read binary data files ?

    I need convert the read data in int, int8, int16 or short, int32 or long and int64.
    I use

    int fgetc( FILE *stream );
    wint_t fgetwc( FILE *stream );



    but this function only read int8 and short. Regard



  2. #2
    Join Date
    Apr 2000
    Posts
    5

    Re: How do I read binary data files ?

    The way I normally do it is use the fstream class as follows:


    fstream fileStrm;

    fileStrm.open(czFileName,ios::in | ios:ut | ios::binary);

    int myInt;
    float myFloat;
    short myShort;

    fileStrm.read((char*)&myInt,sizeof(myInt));
    fileStrm.read((char*)&myFloat,sizeof(myFloat));
    fileStrm.read((char*)&myShort,sizeof(myShort));




    If you look up the documentation for fstream::read, the arguments are very straight forward.

    Hope that helps.


  3. #3
    Join Date
    Jan 2001
    Posts
    12

    Re: How do I read binary data files ?

    Hey,
    Can we use >> and << to input and output a
    binary file?
    Thanks.

    Warren


  4. #4
    Join Date
    Mar 2001
    Location
    BFE
    Posts
    101

    Re: How do I read binary data files ?

    Yes.

    Dave Volland

    That which does not kill us makes us stronger. Or smarter.

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