C++ 在c+;中包含library database.txt文件时出错+;

C++ 在c+;中包含library database.txt文件时出错+;,c++,C++,我正在制作一个图书馆管理系统,包括包含图书和图书分配信息的文本文件。但它显示了一个错误。我有一个database.txt文件,其中给出了书的名称和分配。请帮忙 我的代码是 #include<iostream.h> #include<conio.h> #include<fstream.h> #include "C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt"

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

我的代码是

    #include<iostream.h>
    #include<conio.h>
    #include<fstream.h>
    #include "C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.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]}
#包括
#包括
#包括
#包括“C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt”
字符名[20];
炭书[20];
人物[20];
作废搜索簿()
{
河流充填;
infle.open(“librarydatabase.txt”);
coutname;
填充>>名称;

不能从代码中删除以下行

#include "C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt"
及 换线

infile.open("librarydatabase.txt");


从代码中删除以下行

#include "C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt"
及 换线

infile.open("librarydatabase.txt");


错误库.CPP 4:无法打开包含文件“C:\ReadSeSungChana\Taby\LabyActudio.txt”,尝试将C++ IDE作为管理员来运行,或者您可以更改代码的目录。将其保存到其他驱动器,并且丢失文件操作模式,如“R”、“W”、“A”。您不能包含作为数据源的文件!您应该像在
infle.open(“librarydatabase.txt”)行中那样加载它
即使您能够包含此文件,也会出现编译错误。@Marcin您能建议我编辑的代码吗?这将非常有用。您需要了解
#include
实际上做了什么。错误库.cpp 4:无法打开包含文件“c:\users\RITESH SINGH CHAUHAN\Desktop\librarydatabase.txt”尝试运行C++ IDE作为管理员,或者您可以更改代码的目录。将其保存到其他驱动器,并且缺少“R”、“W”、“A”等文件操作模式。您不能包含作为数据源的文件!您应该像在代码< > IfLILE中那样加载它。
即使您能够包含此文件,也会出现编译错误。@Marcin您能建议我编辑的代码吗?这将非常有帮助。您需要了解
#include
实际上做了什么。或者至少将
#include
更改为
#定义我的文件
,然后更改为
inflee.open(我的文件)替换上述代码后。
功能搜索簿和addbook不起作用。有人能告诉我原因或共享改进的代码吗?或者至少将
#include
更改为
#define MYFILE
然后
infle.open(MYFILE)
替换上述代码后。函数search books和addbook不起作用。有人能告诉我原因或分享改进后的代码吗。