【发布时间】:2014-11-18 21:15:24
【问题描述】:
#include<iostream>
#include<boost/iostreams/device/mapped_file.hpp>
#include<boost/iostreams/stream.hpp>
#include<windows.h>
int main()
{
/*/----- first part starts here
OPENFILENAMEA ofn;
char szFileName[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = 0;
ofn.lpstrTitle="Open file";
ofn.lpstrFilter ="All Files\0*.*\0";
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile=szFileName;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST ;
if(!GetOpenFileNameA(&ofn))return 0;
//-------- first part ends here---*/
double bytesRead=0;
boost::iostreams::mapped_file_source ifile;
ifile.open("D:\\aaa.mp4");//ofn.lpstrFile should be here as argument
if(ifile.is_open()){
boost::iostreams::stream<boost::iostreams::mapped_file_source> input(ifile);
const int chunksize = 4096;
const int fsize = ifile.size();
const int rest = ifile.size() % chunksize;
const int numberOfchunks = ifile.size() / chunksize;
__int64 bytes[chunksize/sizeof(__int64)];
for (int x=0; x<numberOfchunks; x++){
input.read((char*)bytes, chunksize);
bytesRead += chunksize;
}
if (rest > 0){
input.read((char*)bytes, rest);
bytesRead += rest;
}
input.close();
std::cout << std::endl << bytesRead / (1024*1024) << " MB read" << std::endl;
}
system("pause");
return 0;
}
这让我发疯了,如果“第一部分”没有被注释掉,甚至没有使用“ofn.lpstrfile”打开文件,它就会抛出异常:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector
但如果我注释掉代码的“第一部分”,我还没有使用该文件,就可以毫无问题地读取!请问有什么问题吗?
【问题讨论】:
-
那个异常名称被截断了吗?结束于
error_info_injector -
是的,例外是:boost::exception_detail::clone_impl<:exception_detail::eror_info_injector>> 在内存位置 0x003E7F0