使用 boost 进行 CRC32 校验 - firebird321的专栏 - 博客频道 - CSDN.NET
#include <Windows.h>
#include <iostream>
#include <strstream>
#include <ostream>
#include <list>
#include <string>
#include <boost/crc.hpp>using namespace std;
using namespace boost;void main()
{
HANDLE hFile = ::CreateFile("c://test.txt", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(INVALID_HANDLE_VALUE == hFile)
{
cout << "文件不存在" << endl;
return ;
}//存放到内存中
//取得文件大小(字节)
DWORD dwLen = GetFileSize(hFile, NULL);
char *readBuf = new char[dwLen];
memset(readBuf, 0, dwLen);DWORD dwReadLen;
//将文件内容存放到 readBuf 中
ReadFile(hFile, readBuf, dwLen, &dwReadLen, NULL);boost::crc_32_type result;
//计算一个字符的CRC值
//result.process_byte('a');
//计算字符串的CRC值
//result.process_bytes("abc", 3);
//计算文件的CRC值
result.process_block(readBuf, readBuf+dwLen*sizeof(char));cout << std::hex << std::uppercase << result.checksum() << endl;
::CloseHandle(hFile);
system("pause");
return;
}