I have a file which contains a year and the name of an associated file to be read.
I need to extract the data in the txt file and perform some calculations.
( year data file)
2004 2004data.txt
2005 2005data.txt
2006 2006data.txt
...............................................
Here is what I do. I first declare "char yeardata" and then pass "2004data.txt" to it. Then I call yeardata in ifstream to extract the data inside the file "2004data.txt". The problem is that char yeardata is not constant so I cannot pass the file to it. It doesn't work if I change "char yeardata“ to ”const char yeardata”.
Code:int oldnewcomp_temp(char* lcfile) { using namespace std; int year; char yeardata; ifstream inFile2009b; inFile2009b.open(lcfile); inFile2009b >> year >> yeardata ; inFile2009b.close(); ...... ifstream yearlydata; yearlydata.open(yeardata); ...... yearlydata.close(); return 0; }