c++ - 在 C++ 中包含库 database.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]}
解决方案
从代码中删除以下行
#include "C:\Users\Ritesh Singh Chauhan\Desktop\librarydatabase.txt"
并换行
infile.open("librarydatabase.txt");
到
infile.open("C:\\Users\\Ritesh Singh Chauhan\\Desktop\\librarydatabase.txt");
推荐阅读
- javascript - Heroku 托管数据库
- react-native - 数字字段未在 React 本机短信链接中显示数字
- python - 如何让用户在kivy应用程序中保持登录状态
- python - 在矩阵中生成数独游戏而不是绘制 GUI
- java - 我无法更改 TextSwitcher 字体
- javascript - 用不同数组中的值更新对象的值
- java - 如何在我的 @afterSuite 方法中获取 jenkins 内部版本号
- laravel - Laravel Routes - 如何“重写”?
- tensorflow - NotImplementedError:TPUStrategy.run(fn, ...) 不支持纯粹的急切执行。请确保将函数传递到`strategy.run`
- python - 为什么我的 Kivy 标签没有从 Python 正确更新?