Need some direction on this one if anyone can help me out.
Write a C++ program that reads the input file information as a name list. Compare the entered name with the names in the list.
Step 1. Open an input and an output file.
Step 2. Read contents (26 names) from the input file. (input12.txt)
Step 3. Receive a name from a user and compare it to the names in the list. Show the index number if the name is found in the list. If not found, state that. (See the output example below.)
Step 4. Repeat step 3 until the user decides to quit by typing “quit”.
Step 5. Record the entire session to the output file.
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
usingnamespace std;
int main()
{
string ifilename, ofilename, line;
ifstream inFile, checkOutFile;
ofstream outFile;
char response;
// Input File
cout << "Please enter the name of the file you wish to open :";
cin >> ifilename;
inFile.open(ifilename.c_str());
if (inFile.fail())
{
cout << "The file" << ifilename << "was not successfully opened." << endl;
cout << "Please check the path and name of the file." << endl;
exit(1);
}
else
{
cout << "the file is successfully opened." << endl;
}
// Output file
cout << "Please enter the name of the file you wish to write :";
cin >> ofilename;
checkOutFile.open(ofilename.c_str());
if (!checkOutFile.fail())
{
cout << "A file" << ofilename << "exists.\n Do you want to continue to overwrite it? (y/n) :";
cin >> response;
if (tolower(response) == 'n')
{
cout << "The existing file will not be overwritten." << endl;
exit(1);
}
}
outFile.open(ofilename.c_str());
if (outFile.fail())
{
cout << "The file" << ofilename << "was not successfully opened." << endl;
cout << "Please check the path and name of the file." << endl;
exit(1);
}
else
{
cout << "The file is successfully opened." << endl;
}
// Copy file contents from inFile to outFile
while (getline(inFile, line))
{
cout << line << endl;
outFile << line << endl;
}
// Close Files
inFile.close();
outFile.close();
}//main