ifstream cannot locate file

Here is the opening code I am working with:

ifstream inputFile;
string filename;

cout << " Tablerock Member Services" << endl;
cout << "***************************\n\n" << endl;
cout << " Please enter the name of the member file: ";
cin >> filename;

inputFile.open(filename);

The filename is MemberInfo.txt (I unhid the tail end, but I did try a direct path, MemberInfo, MemberInfo.txt, and MemberInfo.txt.txt)

It's is the the current directory, and no matter what I try, it still won't open.

Any suggestions?
A few things...

it depends on what program you use to write your code but for me it needs to be in a certain folder for it to work. be sure you have it in the right place.

make sure everything is right including capitalization and directory.

it could depend on what data is in the text file but it could be how you are putting it into your data type. just make sure do double check everything.

a good way to check to see if it is really opening and fiding the file you could write

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout << " Tablerock Member Services" << endl;
cout << "***************************\n\n" << endl;
cout << " Please enter the name of the member file: ";
cin >> filename;


inputFile.open(filename);
      if (filename.is_open()) {
            cout << "it is open";
      }
      else {
            cout << "it is not open";
      }
      cin.get();


then depending if it gave you the message you want it to then it is a how you are storing it into data rather than if it is opening problem.

I hope I could help!
Last edited on
Topic archived. No new replies allowed.