我正在寻找以二进制格式读取数据文件的最有效方法,然后在文件中搜索模式(标题)的出现。我已使用 cplusplus.com 示例将文件读入内存:
#include <iostream>
#include <fstream>
using namespace std;
ifstream::pos_type size;
char * memblock;
int main () {
ifstream file ("example.bin", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
}
else cout << "Unable to open file";
return 0;
}
首先,我想知道这是否是出于我的目的这样做的最佳方式。如果是,我无法找到如何搜索 0x54 0x51 之类的模式,或者它在 memblock char 数组中的二进制等价物。