Saving File Help

Started by
1 comment, last by levijgraham 12 years, 4 months ago
Hello im trying to save the chuncks of my map in in the folder called level each chunk is supposed to be represented by a diffrent file but i cant seem to figure out how to get what number my loop is on to save in with my file name so i end up getting files called all sorts of names that i dont want.


void Map::Save()
{
for(int loop = 0; loop < Map::AmountOfChuncks;loop++)
{
for(int loop2 = 0; loop2 < Map::AmountOfChuncks;loop2++)
{
ofstream file( "Level/Chunck"+loop+"_"+loop2".Data" );
Map::GenerateChunck();
for(int loop3 = 0; loop3 < Map::AmountOfChuncks;loop3++)
{
for(int loop4 = 0; loop4 < Map::AmountOfChuncks;loop4++)
{
file << Map::Data[loop3][loop4];
}
}
file.close();
}
}}
Advertisement
You cannot concatenate c-strings and integers in that way.

One way to do it is:


std::stringstream ss;

ss << "Level/Chunk" << loop1 << "_" << loop2;

std::ofstream file(ss.str().c_str());
amazing thank u i couldnt figure that out for the life of me :P

This topic is closed to new replies.

Advertisement