基本上我希望能够加载文本文件。这可以。但我想将文本文件放在项目文件夹内的文件夹中。事实证明这是一个问题,因为一旦移动文件,我就无法加载它。我试过输入路径,但我只是得到一个运行时。任何人都可以帮我解决这个问题。
这是我的代码:
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<< "\n\t******Menu******\n\n";
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!");
}
}