Saving to file

Started by
2 comments, last by NukeCorr 16 years, 6 months ago
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;
}

What the h*ll are you?
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 << " ";	}}
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

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

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 :)
What the h*ll are you?

This topic is closed to new replies.

Advertisement