I am not using any spaces in the filename. The file is called scores, and I put the file in all directories of the project just to make sure. I will display the output at the bottom. I realize I have not cloded it yet.
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char reply;
ifstream infile;
string myfile;
char process[200];
ifstream inputFile;
cout << "enter file name: ";
cin >> myfile;
//inputFile.open (inputFileName, ios::in);
inputFile.open (myfile.c_str(), ios::in);
if(!inputFile)
{
cerr << "Can't open input file " << myfile << endl;
cin >> reply;
exit(1);
}
while(inputFile)
{
inputFile.getline(process,200);
cout << "Contents of file are:" << process;
}
cin >> reply;
return 0;
}
Running the program:
Code:
enter file name: scores
Can't open input file scores