ユーザーにファイル名の入力を求めています。最初に有効なファイル名を入力すると、機能します。ただし、最初に無効な場合、他のすべてのチェックは失敗します。どうすればこれを修正できますか? また、ディレクトリを指定したとしましょう。すべてのテキスト ファイルの名前とその数を取得するにはどうすればよいでしょうか。
int main() {
ifstream inFile;
int result;
string filename;
cout << "If the executable is not in the same directory as the\nfile, then a directory needs to be provided\n\n";
while (true) {
cout << "Enter the file name: ";
getline(cin, filename);
inFile.open(filename.c_str(), ios::in);
if (!inFile)
cout << "\n**File failed to open**\n\n";
else break;
}
result = countLOC(inFile);
cout << "\nThere are " << result << " lines of code in \"" << filename << "\"\n\n";
inFile.close();
return 0;
}