Hey I am working on a game that allows saves in it, and long story short I was wondering if it was possible to have a dynamic path name. I know this sounds confusing so let me try to explain it.
right now instead of doing something like:
1 2 3
for( int i = 0; i < 5; i++ ) {
file[i].open("saves/world"i"/player/health.txt");
}
Is there a way to do this efficiently with arrays and for loops? I use this combo a lot in my program because by changing one constant I can change how many skeletons are on the map (for example). This is the only part where I don't know how to do it, and it is slowing down development like crazy.
ofstream file[5];
void open_files();
int main()
{
open_files();
return 0;
}
void open_files()
{
for (int i=0; i<5; i++)
{
stringstream s;
s << "saves/world" << i << "/player/health.txt";
file[i].open(s.str().c_str());
}
}
if you need to call this in multiple source files then you may want to put the ope_files function in seperate header and cpp file and declare the array of ofstream objects as extern.