📄 booksearch.cpp
字号:
//************************************************
// 查找一本书,存在则打印出来,不存在给出提示
//************************************************
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include"book.h"
int match(char *);
void booksearch()
{
book p;
int flag=-1,i=0;
char cname[51]={0};
system("cls");
cout<<"\n\n\t请输入你要查找书的书名:";
cin>>cname;
cin.ignore();
cout<<endl;
flag=match(cname);
if(flag==0)
{
cout<<"\n\n\t查无此书!"<<endl;
system("pause");
return; //返回上一层菜单
}
fstream file("book.dat",ios::in|ios::binary);
if(!file) //错误处理及提示
{
cout<<"\n\t\t打开文件失败!"<<endl;
exit(1); //意外终止程序运行
}
file.read((char*)&p,sizeof(p));
while(!file.eof())
{
if(strcmp(cname,p.getbookname())==0)
{
system("cls");
cout<<"第"<<++i<<"本书的信息:"<<endl;
cout<<p;
system("pause");
}
file.read((char*)&p,sizeof(p));
}
if(file.eof())
{
cout<<"\n\t\t查找结束!"<<endl;
}
file.close();
system("pause");
system("cls");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -