【发布时间】:2014-12-16 22:52:19
【问题描述】:
我在 Tutorial 之后使用 boost 库将一个二进制文件映射到内存中,但现在我无法弄清楚如何以与直接打开它时使用 ifstream 相同的方式迭代二进制对象:
这是代码
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
...
file_mapping m_file(SHMFILE.c_str(), read_write);
mapped_region region(m_file, read_write);
我想做这样的事情:
ifstream myfile (region.get_address(), std::ios::in);
struct stat filestatus;
sstemp = filename.str();
const char * c = sstemp.c_str();
stat(c, &filestatus);
size = filestatus.st_size;
int cant = 0;
while (cant < size)
{
myfile.read((char *) user_id, 4);
cant += 4;
}
有什么办法吗?
【问题讨论】: