Help on file read

Hi, I am writing several numbers into a .dat file and then read them.
But I find out if write a '282' int number into the dat file, I'll read out '0'. Other integer numbers, such as 270, are fine. Does anyone have any ideas what's going on? Thanks a lot!

partial write file example code
1
2
3
4
5
6
7
8
            pFile = fopen(fpath, "wb");
            nAlineNum = 282;
            if (pFile) {
                fwrite(dataname, sizeof(char), 32, pFile); // 32
                fwrite(&nFrameNum, sizeof(int), 1, pFile); // 4
                fwrite(&nAlineNum, sizeof(int), 1, pFile); // 4



read file example code
1
2
3
4
5
6
7
8
9
    ifstream fs;
    fs.open(fpath, std::ios::in);
    if (fs.is_open()) {
        fs.seekg(32, ios_base::beg);
        fs.read((char*)(&nFrameNum), sizeof(int));
        fs.read((char*)(&nAlineNum), sizeof(int));
        fs.close();
    }
Topic archived. No new replies allowed.