Jump to content
  • Advertisement
Sign in to follow this  
NukeCorr

Saving to file

This topic is 4037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I successfully load from a txt file which contains this kind of data: 01 00 00 00 07 00 10 01 01 09 ... etc. But when I save to the txt file, it saves it wrong, like this: 01000000070010010109 ... etc What I need to edit here to save it correctly?
int Tiles[TILES_Y][TILES_X];
bool CTileMap::Save(std::string filename)
{
	int i, c;

	std::ofstream MapFile;
	MapFile.open(filename.c_str());

	for(i=0;i<TILES_Y;i++)
	{
		for(c=0;c<TILES_X;c++)
			MapFile << Tiles[c];
	}

	MapFile.close();

	return true;
}

Share this post


Link to post
Share on other sites
Advertisement
Looks like you just need to store a space between elements.


for(i=0;i<TILES_Y;i++)
{
for(c=0;c<TILES_X;c++)
MapFile << Tiles[c] << " ";
}


Edit: Oops, you need to do it after every other character:


for(i=0;i<TILES_Y;i++)
{
for(c=0;c<TILES_X;c++)
{
MapFile << Tiles[c];

// if c is odd
if(!(c % 2))
MapFile << " ";
}
}

Share this post


Link to post
Share on other sites
I haven't wrote c++ in quite some time but try this;

bool CTileMap::Save(std::string filename)
{
int i, c;

std::ofstream MapFile;
MapFile.open(filename.c_str());

for(i=0;i<TILES_Y;i++)
{
for(c=0;c<TILES_X;c++)
{
MapFile << Tiles[c];
//You need to put the space character in here
MapFile << ' ';
}
}

MapFile.close();

return true;
}



Again I am not positive this will work since its been such a long time but that is the idea of what you need to do, you need to add a blank space character after it reads/prints the array.

Hope it helps;

XXChester

Share this post


Link to post
Share on other sites
I got it working good with this:
	for(i=0;i<TILES_Y;i++)
{
for(c=0;c<TILES_X;c++)
{
MapFile << Tiles[c];
MapFile << " ";
}
}


Thanks for help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!