• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Amber❤
博客园    首页    新随笔    联系   管理    订阅  订阅

c++文件读写

经历一系列会了忘会了忘我要把你记下来啦啦啦啦~不会忘啦~~~

写入文件:

void Card::Save()
{
ofstream outfile("card.dat",ios::out|ios::app);
if(!outfile)
{
cerr << "open error!" << endl;
exit(1);
}
outfile<<name<<" "<<number<<" "<<sex<<" "<<position<<" "<<balance<<" "<<loss<<" "<<kind<<" "<<password<<endl;
outfile.close();
}

 

ios::app  追加文件写入

 

从文件导入内存:

void Management::Output()
{
ifstream CardFile("card.dat",ios::in);
if(!CardFile)
{
//exit(1);
return;
}
string name,sex,kind,position;
int password;
long num;
bool loss;
double balance;
User *user=NULL;
while(CardFile>>name>>num>>sex>>position>>balance>>loss>>kind>>password)
{
cout<<"姓名:"<<name<<endl;
cout<<"号码:"<<num<<endl;
cout<<"类别:"<<kind<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"单位:"<<position<<endl;
cout<<"余额:"<<balance<<endl;
cout<<"是否挂失:"<<loss<<endl<<endl;
user = new User(num,name,sex,kind,position,password,balance,loss);
order.push_back(user);
}
CardFile.close();
}

 

还有一个好玩的东西:cout << "\x07"<< "\x07"<< "\x07"<< "\x07";发粗声音!

posted @ 2013-09-07 10:33  Amber❤  阅读(183)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3