Reading in 4 bytes at a time

前端 未结 5 1489
暗喜
暗喜 2021-01-05 01:54

I have a big file full of integers that I\'m loading in. I\'ve just started using C++, and I\'m trying out the filestream stuff. From everything I\'ve read, it appears I c

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 02:16

    Is this what you mean? By the way, your code (and this) assumes native endianness of the data.

    const int HRSIZE = 129951336;  //The size of the table
    int dhr[HRSIZE/sizeof(int)];   //The table
    
    int main()
    {
        ifstream fstr;
    
        /* load the handranks.dat file */
        std::cout << "Loading table.dat...\n";
        fstr.open("table.dat");
        fstr.read((char*)dhr, HRSIZE);
        fstr.close();
    }
    

提交回复
热议问题