Using C++ to read a data file stored in 16-bit format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randomcz
    New Member
    • Oct 2006
    • 5

    Using C++ to read a data file stored in 16-bit format

    Hi,


    I am trying to use C++ to read a file stored in 16-bit format. It looks like :
    "D6 CD 2F 01 52 07 01 00-52 07 01 00 52 07 01 00" under a hex editor.

    The first variable have 4 bytes: "D6 CD 2F 01". It essentially reprents "19910102"
    the second variable have 1 byte...etc.

    So the problem is how to read it using C++?


    THanks,
    Zheng
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by randomcz
    Hi,


    I am trying to use C++ to read a file stored in 16-bit format. It looks like :
    "D6 CD 2F 01 52 07 01 00-52 07 01 00 52 07 01 00" under a hex editor.

    The first variable have 4 bytes: "D6 CD 2F 01". It essentially reprents "19910102"
    the second variable have 1 byte...etc.

    So the problem is how to read it using C++?


    THanks,
    Zheng
    Take a look at the iostream library to get an undestanding of how to read the files in C++
    Try some code after that and if u face difficulties coe back here again

    Raghuram

    Comment

    • ravenspoint
      New Member
      • Jul 2007
      • 111

      #3
      If this is a school assignment you will probably have to hack around with iostream or something, as Raghuram says.

      In the real world we use fread()

      [CODE=cpp]fread(
      p, // point to buffer for storing data
      4, // size of data items
      N, // number of items
      fp ); // file pointer[/CODE]

      This works in C and C++

      Comment

      Working...