私はCS106Lコースリーダーから小さなゲームを書いています。私はClionとWindowを使います。
私はmain.cpp
などの直接の場所にlevel.txt
を置いていますが、level.txt
というより、ファイルを読むためにフルネームを入力する必要があるのはなぜですか? コアコードは次のとおりです。
`` `CClion - 完全なパスを入力する必要があるのはなぜですか?
void readCorrectFile(ifstream& input) {
// Read the user's prompt until user prompt the right file.
while (true) {
cout << "Enter the file name: ";
string filename;
getline(cin, filename);
// Find if it's a valid name
input.open(filename.c_str());
if (input.is_open()) {
return;
}
// Show info about read file.
cout << "Sorry, we cannot find: " << filename << endl;
input.clear();
}
}
ありがとうございました。 –
@KerwinXiaoはそのような場合に典型的に答えを受け入れるでしょう。ポイント、貴重なポイント。 –