在 C++ 中包含库数据库.txt文件时出错

error in including library database.txt file in c++

本文关键字:文件 出错 txt 数据库 C++ 包含库      更新时间:2023-10-16

我正在制作一个图书馆管理系统,包括包含书籍信息和书籍分配信息的文本文件。但它显示错误。我有一个数据库.txt文件,其中给出了书籍的名称和书籍的分配。请帮忙...

我的代码是

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include "C:UsersRitesh Singh ChauhanDesktoplibrarydatabase.txt"
char name[20];
char book[20];
char person[20];
void searchBook()
{
ifstream infile;
infile.open("librarydatabase.txt");
cout<<"enter name of book";
cin>>name;
infile>>name;
cout<<name<<endl;
infile.close();
}
void addNewBook()
{
ofstream outfile;
outfile.open("librarydatabase.txt");
cout<<"enter name of book";
cin>>book;
outfile<<book<<endl;
cout<<"successfully added";
outfile.close();
}
void allotmentList()
{
cout<<"enter name of person";
cin>>person;
}
void exitLib()
{
//exit();
}
void main() 
{
clrscr();
int number;
cout<<"press 1 to search book"<<" "<<"press 2 to add a new book"<<" " 
<<"press 3 to allotment list by person"<<" "<<"press 4 to exit";
cin>>number;
switch(number)
{ 
case 1: searchBook();
break;
case 2: addNewBook();
break;
case 3: allotmentList();
break;
case 4: exitLib();
break;
default: cout<<"press number between 1 to 4";
}
[code is showing error and an error message is given in image][1]}

从代码中删除以下行

#include "C:UsersRitesh Singh ChauhanDesktoplibrarydatabase.txt"

和 更改行

infile.open("librarydatabase.txt");

infile.open("C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt");