📄 readerhistory.h
字号:
#ifndef READERHISTORY_H
#define READERHISTORY_H
#include<fstream.h>
class readerhistory
{
public:
void save(char *a , bool b , book c )//保存读者的借阅历史
{
strcpy(number,a);
bo = c ;
condition = b ;
fstream f( "d:\\history.dat" , ios::binary|ios::in|ios::out ) ;
f.seekg( 0, ios::end ) ; // 读指针移到文件末尾
f.write( (char *) & (*this) , sizeof(*this) ) ; // 写入文件
}
void print()
{
int sg = 0 ;//标志
char key[10] ;
fstream f( "d:\\history.dat" , ios::binary|ios::in|ios::out ) ;
f.seekg( 0, ios::end ) ; // 读指针移到文件末尾
long posEnd = f.tellg() ; // 记录文件尾位置
f.seekp( 0, ios::beg ) ; // 读指针移到文件开始
cout << "请输入你要查询的帐号: " ;
cin >> key ;
do
{
f.read((char *) & (*this) , sizeof(*this)) ;
if( !strcmp(number,key) )
{
sg = 1 ;
cout << "读者帐号为: " << number << endl ;
cout << "图书编号为: " << bo.getcode() << endl ;
cout << "图书名称为: " << bo.getname() << endl ;
cout << "该图书" ;
if( condition == false )
cout << "已还!" << endl ;
else
cout << "未还!" << endl ;
}
} while ( f.tellg() != posEnd ) ; //遍历查找
if( !sg )
cout << "没有该读者借阅信息!" << endl ;
}
private:
char number[10] ;
book bo ;
bool condition ;
} ;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -