I'm confused about how to open/access a file using Notepad++
and the cmd with MinGW
compiler. I understand the file needs to be in the same scope however, I'm not sure where. I have tried placing the .txt
file in my Documents
folder which also holds the main.cpp
file, and I have tried placing it in the bin
folder of the MinGw
folder. When I run the code, I get the error message. Is something wrong with my code or is the .txt
file in the wrong location?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFS;
ofstream outFS;
string fileName;
double fileNum;
//fileName = "input_prac.txt";
//cout << "Enter file name: " << endl;
//cin >> fileName;
cout << "Opening file..." << endl;
inFS.open("input_prac.txt"); // Open file
if (!inFS.is_open())
{
cout << "Could not open file" << endl;
exit(1);
}
// Read file
while(!inFS.eof())
{
inFS >> fileNum;
cout << fileNum << endl;
}
inFS.close(); // close file
return 0;
}