7.5
来源:互联网 发布:沈阳软件大厦 编辑:程序博客网 时间:2024/04/29 07:13
#include <iostream> #include <fstream> using namespace std; typedef struct staff { int num; char name[20]; int age; double pay; }; int main() { staff staf[7]={2101,"Li",34,1203,2104,"Wang",23,674.5,2108,"Fun",54,778,3006,"Xue",45,476.5,5101,"Ling",39,656.6},staf1; fstream iofile("stu.dat",ios::in|ios::out|ios::binary); if(!iofile) { cerr<<"open error!"<<endl; abort(); } int i,m,num; cout<<"Five staff :"<<endl; for(i=0;i<5;i++) {cout<<staf[i].num<<" "<<staf[i].name<<" "<<staf[i].age<<" "<<staf [i].pay<<endl; iofile.write((char *)&staf[i],sizeof(staf[i]));} cout<<"please input data you want insert:"<<endl; for(i=0;i<2;i++) {cin>>staf1.num>>staf1.name>>staf1.age>>staf1.pay; iofile.seekp(0,ios::end); iofile.write((char *)&staf1,sizeof(staf1));} iofile.seekg(0,ios::beg); for(i=0;i<7;i++) {iofile.read((char *)&staf[i],sizeof(staf[i])); cout<<staf[i].num<<" "<<staf[i].name<<" "<<staf[i].age<<" "<<staf [i].pay<<endl; } bool find; cout<<"enter number you want search,enter 0 to stop."; cin>>num; while(num) { find=false; iofile.seekg(0,ios::beg); for(i=0;i<7;i++) {iofile.read((char *)&staf[i],sizeof(staf[i])); if(num==staf[i].num) { m=iofile.tellg(); cout<<num<<" is No."<<m/sizeof(staf1)<<endl; cout<<staf[i].num<<" "<<staf[i].name<<" "<<staf[i].age<<" "<<staf [i].pay<<endl; find=true; break; } } if(!find) cout<<"can't find "<<num<<endl; cout<<"enter number you want search,enter 0 to stop."; cin>>num; } iofile.close(); return 0; }
0 0
- 7.5
- 7.5
- 7.5
- 7.5
- 7.5
- 7.5
- 7.5
- 7.5
- 7.5
- MyEclipse 7.5
- 7.5日志
- 7.5注解
- 7.5 魔板
- cuda 7.5
- 7.5 Map
- 7.4 7.5
- 7.5 日志
- 7.5.1
- 黑马程序员——Java基础---IO概述
- megento api soap xmlrpc接口 自定义扩展 Creating a Custom API or Extending the Core API
- MyBatis数据持久化(四)类型别名
- 二叉树的遍历
- 梦起始的地方
- 7.5
- j2se学习笔记-多态(动态绑定)
- Implementation of Self-signed SSL certificate for your App.
- android stutio项目如何导入Eclipse中,完美解决
- 临终病人最后悔的五件事
- 开始学习C++心得实例(3)
- 第008讲 div css开山篇
- j2se学习笔记-抽象类
- Linux 网络编程之通过IP或者主机名获取信息