Hello, I am making a project and this part where I need to ask the user to input the .txt file name and read each words to array. but before that when I enter the correct file name there's nothing wrong.**but if I enter incorrect filename and re-enter a correct file name but it won't continue and keeps asking to enter the correct file name
// this is function
string read_file(string& fileName) //option2
{
//ofstream outData;
cin.clear();
cout << "Enter the data file Name : " << endl;//asks user to input filename
cin >> fileName; //inputs user input into fileName
fileName = fileName+".txt";
cout << "reading file now : "<< fileName <<endl;
return fileName;
}
//this is in main();
case 2:
{ system("cls");
read_file(fileName);
inData.open(fileName.c_str());// opens the file with the users input
//outData.open(fileName.c_str());
while(inData.fail())
{
inData.clear();
cout<<"Incorrect filename, please enter again";
cin>>fileName;
inData.open(fileName.c_str());
}
while (!inData.eof() && !inData.fail() && i<100)
{
string filewords[100];
for (int i=0;i<100;i++)
{
inData>>filewords[i];
}
}