This is for a betting predictor I am making purely for a challenge.
As I have all the data I need from previous real matches in csv files I need to specify which file it is within runtime.
For instance, if I want to see the probability that Team A beats Team B then I need to get data from the csv file with these teams in. If they are German teams for instance, then the file "germany.csv".
I have a function for setting the file which returns a char pointer of the filename like this:
Then in other functions where I need to use this file I have the code
Can anyone spot why this doesnt open up the specifed file? It seems to get to the while loop and never get to the end of the file. However, the data reading works if i type ifstream statfile (filename) globally at the top of the source file, but I obviously cannot enter the filename into the code as a user when I run the program.
As I have all the data I need from previous real matches in csv files I need to specify which file it is within runtime.
For instance, if I want to see the probability that Team A beats Team B then I need to get data from the csv file with these teams in. If they are German teams for instance, then the file "germany.csv".
I have a function for setting the file which returns a char pointer of the filename like this:
char* StatLib::setFile(int filenumber)
{
char* charPtr;
if(filenumber==1)
{
charPtr="B1.csv";
}
return charPtr;
}
// obviously I will include more cases and add exception handlingThen in other functions where I need to use this file I have the code
char* filename=setFile(_filenumber);
ifstream statfile;
statfile.open(filename);
statfile.clear();
statfile.seekg(0);
while(!statfile.eof())
{
// data reading
}
Can anyone spot why this doesnt open up the specifed file? It seems to get to the while loop and never get to the end of the file. However, the data reading works if i type ifstream statfile (filename) globally at the top of the source file, but I obviously cannot enter the filename into the code as a user when I run the program.