簡體   English   中英

文件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<< "\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!");                                                             
        }
}

如果要使用雙斜杠\\\\來保存所有麻煩,即使在Windows下,也可以使用一個正斜杠/代替。

我遇到的問題是我沒有逃脫斜線。 在C ++中,斜線用於\\ n或\\ t之類的內容。 因此,基本上只有一個\\對編譯器毫無意義。 我需要這樣做:“文本文件\\\\ Introduction.txt”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM