我正在使用C++開發一個項目。如何使用ofstream在另一個目錄中寫入文件?
在我的當前目錄中還有另外一個文件夾,名爲game_files和game_files裏面有一個名爲player_name.txt
在我的cpp文件(Kingdom.cpp)我有以下
std::string playerName;
std::cin >> playerName;
std::ofstream nameFile;
nameFile.open("/game_files/player_name.txt")
nameFile << playerName;
nameFile.close();
代碼文件
但是當我檢查文件時,沒有寫入任何文件! 我一直在尋找答案一段時間,我完全失去了。
任何和所有的幫助表示讚賞,謝謝!
你應該檢查你的流與'失敗'的初學者。你正在寫系統的根目錄,而不是在一個子目錄中 –