7.5
来源:互联网 发布:金融信息数据库 编辑:程序博客网 时间:2024/05/15 01:23
#include <iostream>#include <fstream> using namespace std; struct staff {int num; char name[20]; int age; double pay; }; int main() { staff staf[7]={2001,"Li",34,1200,2002,"Wang",23,2222,2003,"Fun",33,3333, 3333,"Xue",45,4444,5555,"Ling",39,6666},staf1; fstream iofile("staff.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
- OSG实现跟随节点的相机
- static函数与普通函数
- JFrame - swing创建一个空窗体
- cookies session application三种状态对象的使用及区别(Application,Session,Cookie)
- SOCKET编程-java
- 7.5
- 我和我的朋友
- Java foreach语句
- 充值与代购渠道统一配置处理思路
- android开发步步为营之62:进程间通信之Aidl
- Response.Redirect进入文件夹
- fmt:formatDate的输出格式详解
- 2015-06-09学习情况
- Android自动登录界面