I am reading a text file which has two columns of data. The following program works when readfile.open(afile) is replaced simply with readfile.open("001.txt"). Why does it not work when I declare afile beforehand? Although it may not seem important for this particular code, it is necessary for my future tasks. Thank you in advance.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main (){
string afile = "001.txt";
ifstream readfile;
readfile.open(afile);
const int n = 10;
double x[n], y[n];
for (int i=0; i<n; i++)
{
readfile>>x[i]>>y[i];
cout<<x[i]<<" "<<y[i]<<endl;
}
readfile.close();
}