文件 I/O.无法使用文件的路径
File I/O. Not able to use path of the file
基本上我希望能够加载文本文件。 这很好。 但是我想将文本文件放在项目文件夹内的文件夹中。 这被证明是一个问题,因为一旦文件被移动,我就无法加载它。 我尝试输入路径,但我只是得到了一个运行时。 任何人都可以帮我解决这个问题。
这是我的代码:
Storyline::Storyline()
{
mStory = "Default";
}
Storyline :: Storyline(string story)
{
mStory= story;
}
void Storyline::print()
{
cout<< "Story= " << mStory<< endl;
cout<< endl;
}
void Storyline::save(ofstream& outFile)
{
outFile<< "Story = " << mStory<< endl;
outFile<< endl;
}
void Storyline::load(ifstream& inFile)
{
string garbage;
inFile>> garbage >> mStory;
}
void Storyline::Menu()
{
cout<< "nt******Menu******nn";
cout<< "Please choose one of the following:n";
cout<< "1 -Play Game.n";
cout<< "2 -Exit.n";
}
void Storyline::Story(string story)
{
ifstream Story;
string line;
Story.open(story);
if (Story.is_open())
{
while ( Story.good() )
{
getline (Story,line);
cout << line << endl;
}
Story.close();
}
else{
throw("GAME FILE LOADING FAILED!");
}
}
如果你想使用双斜杠 \\ 来省去所有的麻烦,你可以使用一个正斜杠/代替,即使在 Windows 下也是如此。
我遇到的问题是我没有逃脱我的斜杠。 在C++中,对于 或 \t 之类的内容,将读取斜杠。 所以基本上只有一个\对编译器没有任何意义。 我需要这样做:"文本文件\\简介.txt"
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 在C++中设置基于操作系统的文件路径
- Windows 非 ASCII 文件路径
- 非 ASCII 文件路径窗口
- C++和带有国家符号的文件路径(也许用 UTF8 编码)
- 如何为文件路径使用变量?
- 包括 VS Code 上的完整文件路径
- 如何使用提升获取当前文件路径?
- 如何在 c++ 中获取当前文件路径?
- 保存json文件后如何返回文件路径
- 从 C++ 中的文件路径中提取文件名
- 是否可以将文件路径传递给Qt中的setStyleSheet()
- 无法转换 .CATPart 文件.错误:输入文件路径似乎包含不支持的字符
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 提供依赖于输入的程序的文件路径
- 从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
- 如何更改变量文件名的文件路径?
- cmake:包括vs vs add_subDirectory:相对标头文件路径
- 在OSX中使用CGDisplayStream存储屏幕记录的特定文件路径
- 如何在另一个系统上启用文件路径