Reading binary file defined by a struct

后端 未结 5 1775
轻奢々
轻奢々 2021-02-11 01:23

Could somebody point me in the right direction of how I could read a binary file that is defined by a C struct? It has a few #define inside of the struct, which makes me thing t

5条回答
  •  醉酒成梦
    2021-02-11 01:56

    Using C++ I/O library:

    #include 
    using namespace std;
    
    ifstream ifs("file.dat", ios::binary);
    Format f;
    ifs.get(&f, sizeof f);
    

    Using C I/O library:

    #include 
    using namespace std;
    
    FILE *fin = fopen("file.dat", "rb");
    Format f;
    fread(&f, sizeof f, 1, fin);
    

提交回复
热议问题