Reputation: 29
I'm writing a program that uses <fstream>
. The file I need to include is called employee.dat and it's listed in the directory. I put in a cout
statement that says:
ifstream inFile ("EMPLOYEE.DAT");
if (! inFile)
{
cout << "!!Error in opening 'EMPLOYEE.DAT"<< endl;
}
The file is in the directory and there shouldn't be any issues opening/finding it. This is my first time using the ifstream
class.
Upvotes: 1
Views: 5583
Reputation: 1200
Beware that in Visual Studio, the Working Directory (set in the project properties under the Debugging tab) is the location that the exe is apparently located when debugging (and not the actual location of the exe itself)
Upvotes: 1
Reputation: 63481
If you are running from the Visual Studio environment, be aware that your executable probably isn't in the same directory as your data file. Binaries tend to be built into a Debug
or Release
folder by default. You have several options:
It's also possible that you are looking in the right place, but the file is locked. Make sure it's not open in any editor or other program that might prevent other processes from opening it.
Upvotes: 3