• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
chance的博客
   首页    新随笔    联系   管理    订阅  订阅
方法:将一个对象放入一个固定大小的空间中

1、引入

fstream iofile("DiskSystem\\haha.txt",ios::in|ios::out|ios::binary);
char * n = (char *)malloc(1024);
n = "hello worldfdgfdgfdgfdgfdgfdgfd";
iofile.write(n,1024);

iofile.seekg(ios::beg);
char * s = (char *)malloc(1024);
iofile.read(s,1024);
iofile.close();
cout<<s<<endl;

 

2、换成对象

class Test
{
public:
Test(char * c = "Test"):s(c){};
char *s;
};

Test * t = (Test *)malloc(1024);
t->s = "Hello World";

fstream iofile("DiskSystem\\haha.dat",ios::in|ios::out|ios::binary);
iofile.write((char *)t,1024);

Test * tt = (Test *)malloc(1024);
iofile.seekg(ios::beg);
iofile.read((char *)tt,1024);

cout<<tt->s<<endl;

iofile.close();

posted on 2012-03-07 01:04  Chance_yin  阅读(257)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3