Hello all,
So I am working on a bit of a personal project, and at a stage where I need to display large bodies of text. Naturally hard coding each of this would be tedious and time consuming so I tried to develop the following code to simply cycle through the various .dat files and pirnt which ever one it was told.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void printMission(short missionNum)
{
enum Missions{Mission1=1,Mission2,Mission3,Mission4,Mission5};
bool gotIt=false;
short endPT;
string line;
switch (missionNum){
case Mission1: {ifstream filestream(".\\data\\MissionsIndex\\01.dat");gotIt=true;break;}
case Mission2: {ifstream filestream(".\\data\\MissionsIndex\\02.dat");gotIt=true;break;}
case Mission3: {ifstream filestream(".\\data\\MissionsIndex\\03.dat");gotIt=true;break;}
case Mission4: {ifstream filestream(".\\data\\MissionsIndex\\04.dat");gotIt=true;break;}
case Mission5: {ifstream filestream(".\\data\\MissionsIndex\\05.dat");gotIt=true;break;}
default: {cout <<" Error: Mission Index not found...\n";gotIt=false;break;}
}// end switch
if (gotIt==true){
filestream >> endPT;
for (int lineno = 0; getline (testfile,line) && lineno < endPT; lineno++)
{cout << line << endl;};
}// end If
};
|
In case you are wondering this is a game yes. But is very much so in it's infancy. Now on to the error. What I expected it to do was display a different file based upon which case it jumped to. however when I tried to compile, it returns a 'filestream undeclared: first use in the function' error.
To try to correct, I tried declaring it without a specific file name. The compiler went on it's marry way but displayed no output, which should mean that there was either no file attached or it didn't hit the switch cases.
I implanted a few couts inside the cases to check and found that it does in fact
go through that code and to the correct case as well, but doesn't end up redefining 'filestream'.
Any suggestions on how to allow the cycling to actually define filestream so I could print effectively?
Thanks!
-Ty
* Note on 0X.dat format: the first line of the file contains a number which represents the linecount of the file. When used in the for loop it allows the file to be printed in its entirety.