⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 删除书.cpp

📁 图书馆管理系统 查找
💻 CPP
字号:
#include "stdafx.h"
#include"harRange.h"
#include"BookData.h"
void deleteBook()
{
	fstream file;
	file.clear();

	fstream file2;
	BookData obj;
	string search,oldName;
	file.open("shendan.dat",ios::in|ios::out|ios::binary);
	if(file.fail())
	{
		cout<<"\t\t\t打开文件失败!\n";
		exit(0);
	}
	file2.open("shen.dat",ios::out|ios::app|ios::binary);
	if(file2.fail())
	{
		cout<<"\t\t\t打开文件失败!\n";
		exit(0);
	}
	cout<<"\t\t\t---------------------------\n";
	cout<<"\t\t\t请输入您要查找的书名:";
	cin>>search;
   	file.seekg(0L,ios::beg);
	file.read((char*)&obj,sizeof(obj));
	while(!file.eof())
	{
		
		oldName.assign(obj.getTitle ());
		if(search!=oldName)
		{
			file2.write((char*)&obj,sizeof(obj));	
		}
		file.read((char*)&obj,sizeof(obj));
	}
	file.clear();
	file2.clear();
	file.close();
	file2.close();
	remove("shendan.dat");

	file.open("shendan.dat",ios::out|ios::app|ios::binary);
	if(file.fail())
	{
		cout<<"打开文件失败!\n";
		exit(0);
	}

	file2.open("shen.dat",ios::in|ios::binary);
	if(file2.fail())
	{
		cout<<"打开文件失败!\n";
		exit(0);
	}
	file2.read((char*)&obj,sizeof(obj));
	while(!file2.eof())
	{


		file.write((char*)&obj,sizeof(obj));	
		file2.read((char*)&obj,sizeof(obj));

	}

	file.close();
	file2.close();
	remove("shen.dat");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -