Cpp1.cpp
资源名称:Desktop.rar [点击查看]
上传用户:hnwbjx
上传日期:2022-07-21
资源大小:497k
文件大小:1k
源码类别:
企业管理
开发平台:
Visual C++
- #include <iostream.h>
- #include <fstream.h>
- #include <stdlib.h>
- #include <string.h>
- struct txrec
- { char no[6];
- char name[20];
- char tel[9];
- char postc[7];
- char addr[30];
- };
- void main()
- { struct txrec gzrec; int i;
- char filename[20], num[5];
- fstream infile;
- cout << "请输入通讯录文件名:";
- cin >> filename ;
- infile.open( filename, ios::in|ios::binary );
- if ( !infile )
- { cerr << "文件不能打开!" << endl;
- abort(); }
- infile.seekg( 0,ios::end );
- long posend = infile.tellp();
- infile.seekg( 0,ios::beg );
- cout << "请输入职工编号:" ;
- cin >> num;
- do
- { infile.read(( char * )&gzrec,sizeof( txrec ));
- } while ( strcmp( gzrec.no,num ) !=0 && infile.tellp() != posend );
- if ( strcmp( gzrec.no,num ) == 0 )
- { cout << "该职工的记录找到了!" << endl;
- cout << "编号:" << gzrec.no << endl;
- cout << "姓名:"<< gzrec.name << endl;
- cout << "电话号码:"<< gzrec.tel << endl;
- cout << "邮政编码:" << gzrec.postc << endl;
- cout << "通信地址:" << gzrec.addr << endl;
- }
- else
- { cout << "该职工的记录找不到!" << endl; }
- infile.close();
- }