Skip to main content
GameDev.net gamedev.net
🔒 Locked

Saving File Help

Started by levijgraham Dec 16, 2011 at 10:24 AM 1 replies 1.1k views
Original Post
levijgraham
levijgraham
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();
}
}}
bradbobak
bradbobak
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());
levijgraham
levijgraham
amazing thank u i couldnt figure that out for the life of me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.