稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

vs 2010 如何用boost计算文件的crc值

1. 首先从官网下载boost库,http://nchc.dl.sourceforge.net/project/boost/boost/1.53.0/boost_1_53_0.7z
只使用crc无需编译boost,只需要包含指定的 crc.hpp即可。
2. 下载后解压到d盘:D:\boost_1_53_0
3. 建立控制台工程文件,并做如下设置:
4. 代码如下
// crctest.cpp : 定义控制台应用程序的入口点。
//

#include 
"stdafx.h"

#include 
<Windows.h>
#include 
<iostream>
#include 
<strstream>
#include 
<ostream>
#include 
<list>
#include 
<string>
#include 
<boost/crc.hpp>

using namespace std;
using namespace boost;


void _tmain(int argc, _TCHAR* argv[])
{    
    HANDLE hFile 
= ::CreateFile(_T("c:\\1.zip"), 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);

    delete []readBuf;

    system(
"pause");
    
return;
}
 



posted on 2013-02-13 03:32 AlanTop 阅读(1469) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理