https://blog.csdn.net/changshiyzj/article/details/86606559
void read_file(const string& filename, string & filedata)
{
ifstream infile;
char *fileBuffer = NULL;
infile.open(filename,ios::binary);
if(infile.is_open())
{
infile.seekg(0,ios::end);
auto len = infile.tellg(); //获取文件长度
infile.seekg(0, ios::beg); //设置读取位置为起始位置
fileBuffer = new char[(size_t)len + 1];
memset(fileBuffer,0,(size_t)len + 1);
infile.read(fileBuffer,len);
filedata = fileBuffer;
delete [] fileBuffer;
}
infile.close();
}
————————————————
版权声明:本文为CSDN博主「奔流的江」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/changshiyzj/article/details/86606559