【发布时间】:2010-06-07 02:53:36
【问题描述】:
我有一个充满整数的大文件正在加载。我刚刚开始使用 C++,并且正在尝试使用文件流的东西。从我读过的所有内容来看,我似乎只能以字节为单位读取,所以我必须设置一个 char 数组,然后将其转换为 int 指针。
有没有一种方法可以一次读取 4 个字节,并且不需要 char 数组?
const int HRSIZE = 129951336; //The size of the table
char bhr[HRSIZE]; //The table
int *dwhr;
int main()
{
ifstream fstr;
/* load the handranks.dat file */
std::cout << "Loading table.dat...\n";
fstr.open("table.dat");
fstr.read(bhr, HRSIZE);
fstr.close();
dwhr = (int *) bhr;
}
【问题讨论】:
-
那么你的“充满整数的大文件”实际上是以二进制形式存储的吗?您是否考虑了字节序?
标签: c++