64,654
社区成员
发帖
与我相关
我的任务
分享
string FileDigest(const string &file) {
ifstream in(file.c_str(), ios::binary);
if (!in)
return "";
streampos pos = in.tellg(); // save current position
in.seekg(0, ios::end);
cout << "file length =" << (unsigned long)in.tellg() << endl;
unsigned long dwLen = in.tellg();
in.seekg(pos); // restore saved position
unsigned long dwLenDon = 0;
MD5 md5;
std::streamsize length;
//char buffer[1024000];
char* buffer = new char[1024*1024*100];
while (!in.eof()) {
in.read(buffer, 1024*1024*100);
length = in.gcount();
if (length > 0)
md5.update(buffer, length);
dwLenDon+=length;
cout<< "完成率:" << dwLenDon*100/dwLen<<endl;
}
in.close();
return md5.toString();
}