I think I may not have the file I'm trying to read in the right spot but i've put it everywhere possible in the IDE and it is still not working. Ive even put it next to the .exe for my program and it still cant find it.
I was expecting the file to be able to be opened so I can read its contents with c++ code.
#include <iostream>
#include <fstream>
#include <cstdlib> // exit prototype
#include <iomanip>
using namespace std;
int main(int argc, char* argv[])
{
ifstream inFile;
string filename = "infile6";
// if a filename is provided, open file
cout << "Enter the name of a file to read from: " << endl;
//cin >> filename;
cout << "Name of a file requested: " << filename << endl;
inFile.open(filename.c_str());
if (!inFile)
{
cerr << endl;
cerr << "File cannot be opened" << " " << filename << endl;
exit(1);
}
return 0; // ifstream destructor closes file
} // end main
The default location of projects created with Visual Studio is:
C:\Users\%USERNAME%\Documents\Visual Studio 2022\ProjectsYour binary file is located deep inside that directory tree
Now, your program is expecting the file
infile6to be located in the same directory as your executable(C:\Users\%USERNAME%\Documents\Visual Studio 2022\Projects\RA2\Debug\).You can either copy/paste your file in that directory, or you can provide the absolute path to your
infile6.string filename = "C:\\Users\\Bob\\Documents\\Visual Studio 2022\\Projects\\RA2\\Source Files\\infile6";