I'm prompting the user for a filename, if they enter a valid filename the first time, it works. However, if its invalid the first time, every other check fails. How would I fix this? Also, let's say they just specify a directory, how would I get the names of all the text files and how many there are?
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;
}