gpt4 book ai didi

c++ - 在 C++ 中包含库 database.txt 文件时出错

转载 作者:行者123 更新时间:2023-11-28 01:33:28 25 4
gpt4 key购买 nike

我正在制作一个图书馆管理系统,包括包含书籍和书籍分配信息的文本文件。但它显示错误。我有一个 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]}

最佳答案

从代码中删除以下行

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

和换行

infile.open("librarydatabase.txt");

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

关于c++ - 在 C++ 中包含库 database.txt 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50502146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com