Okay, I\'m trying to read text off a file but I want to add a loopto make sure t
ID: 3616665 • Letter: O
Question
Okay, I'm trying to read text off a file but I want to add a loopto make sure the user enters the correct file name. In the loop Ihave if the name is entered correctly it won't run, if the name isentered incorrectly it will run, if the name is entered correctlyafter it enters the loop it won't get out.#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string fileName;
ifstream inFile;
cout << "Enter a valid file name:";
cin >> fileName;
inFile.open (fileName.c_str());
while (!inFile)
{
cout<< "Re-enter a vliad file name: ";
cin >>fileName;
inFile.open(fileName.c_str());
}