zoukankan      html  css  js  c++  java
  • 使用 boost 进行 CRC32 校验

    使用 boost 进行 CRC32 校验 - firebird321的专栏 - 博客频道 - CSDN.NET

    使用 boost 进行 CRC32 校验

    分类: 文件操作 1362人阅读 评论(0) 收藏 举报
    #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;
    }
  • 相关阅读:
    Java
    HashMap数据结构与实现原理解析(干货)
    Java
    Java
    Java
    面向对象基础
    Java
    Java
    Java
    shell脚本
  • 原文地址:https://www.cnblogs.com/lexus/p/3408272.html
Copyright © 2011-2022 走看看