基本的にテキストファイルを読み込めるようにしたいです。これで問題ありません。しかし、テキストファイルをプロジェクトフォルダー内のフォルダーに入れたいです。ファイルが移動されるとロードできないため、これは問題であることが証明されています。パスを入力しようとしましたが、ランタイムが表示されます。誰でもこれで私を助けることができますか?
これが私のコードです:
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!");
}
}