P269 5
来源:互联网 发布:网络维护工程师工资 编辑:程序博客网 时间:2024/06/08 04:06
#include <iostream> #include <fstream> using namespace std; 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("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
- P269 5
- P269 2
- P269 3
- P269 6
- UVA 437(p269)----The Tower of Babylon
- uva 1347 动态规划DAG lrj-P269
- dp专题 lrj-p269 uva A Spy in the Metro 2003wf
- 5
- 5
- 5
- 5
- 5
- 5
- 5
- 5
- 5
- 5
- 5
- 获取某个网页的源代码显示在手机界面上
- 认识自己——人的野心和目标
- Mybatis学习(六)mybatis与hibernate区别与应用场景
- 匿名函数(function(){})
- J2EE总结(三)——深入理解JSP开发工作原理
- P269 5
- Leetcode[19]-Remove Nth Node From End of List
- Hadoop Balancer源码解读
- 线程与进程的区别
- java执行shell命令,chmod 777 xxx,改变权限无效的解决办法。
- LeetCode 之 Search Insert Position — C 实现
- css判断不同分辨率显示不同宽度布局实现自适应宽度
- c语言中关键字的用法
- VIM使用技巧 ctags taglist