25.文件当做内存来操作

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include <iostream>
 3 #include <boost/interprocess/file_mapping.hpp>
 4 #include <boost/interprocess/mapped_region.hpp>
 5 #include <fstream>
 6 #include <cassert>
 7 #include <cstdlib>
 8 
 9 using namespace std;
10 using namespace boost;
11 
12 //#pragma comment(lib,"libboost_date_time-vc141-mt-sgd-x32-1_66.lib")
13 
14 void main()
15 {
16     //创建读写模式
17     boost::interprocess::mode_t mode = boost::interprocess::read_write;
18     char path[50] = "1.txt";
19     //文件映射
20     boost::interprocess::file_mapping fm(path, mode);
21     //用region访问
22     boost::interprocess::mapped_region region(fm, mode, 0, 0);
23 
24     char *pbegin = reinterpret_cast<char *>(region.get_address());
25     char *pend = pbegin + region.get_size();
26     for (char *p = pbegin; p != pend; p++)
27     {
28         cout << *p << endl;
29     }
30     cin.get();
31 }

 

转载于:https://www.cnblogs.com/xiaochi/p/8690904.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值