Hi all,
before i begin, yes this is an homework assignment question...
got a c++ file I/O question. here is the code that i've so far.
#include <iostream>
#include <sting>
#include <fstream>
int main()
{
string inputFileName;
ifstream inputFile;
cout << "enter file name";
cin >> inputFileName;
inputFile.open (inputFileName.c_str());
// if file fails to open/exist
while(inpuFile == NULL)
{
cout << "enter file name";
cin >> inputFileName;
inputFile.open (inputFileName.c_str());
}
// if the file open successfully, exit loop
return 0;
}
so the purpose is if the input file name entered by the user does not exist or fail to open then keep looping throuh until the file opens.
to test it out, i give the wrong file name so the loop is executed, then i provide the correct file name...it does not open the file and i keep looping through..
i'm probably doing something wrong with ( inputFile == NULL ) condition...please help
thanks in advance
Clicker