Writing Files in Directorys

Started by
2 comments, last by ApochPiQ 13 years, 3 months ago
I have a 3dtile map that is separated into 3d (16x16x16) chunks.
I now need to have these chunks save to a file when they are no longer visible to the user.
I was thinking of saving them as for example save/1-1-1.txt, save/1-1-2.txt, etc.
Then I thought it would be easier to just seperate the x, y, and z locations of the chunks
using directorys like so: save/1/0/0.txt, save/2/0/0.txt, save/3/0/0.txt.

However I have now come to realise fstream does not create folders.

Do I need to use the current approach and create folders when saving?
Do I need to save the origonal way with some char seperating the vars? (seems it may get complicated with big numbers ex: save/101-3-21.txt)

What approach should I take?
keep in mind this has to be compilable on Windows, Mac, and Linux.

Thanks

Current code that doesn't work because folders dont exist:
#include "Global.h"

file::file()
{
////Clear Variables
name.str(std::string());

}
void file::write(int x,int y,int z)
{
name.str(std::string());
name << "save/" << x << "/" << y << "/" << z << ".txt";
//name << x << "-" << y << "-" << z << ".txt";
temp = name.str();
fileStream.open(temp.c_str());
if (fileStream.is_open())
{
//Just something to write
for (int i=100;i>=0;i-=2)
{
fileStream << i << endl;
}
}
else
{
//printf("/!\\ Cannot open \n");
cout << "/!\\ Cannot open " << temp.c_str() << "\n";
fileStream.close();
}
return;
}
If this post was helpful please +1 or like it !

Webstrand
Advertisement
Have a look at boost::filesystem, it should do exactly what you need and quite portably.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

I am trying to do this without adding another library.
Is that possible? It would be much prefered.

I am already using SDL, OpenGL among others.
I want to be able to sell my game without paying anything.

Does Boost allow me to sell my game commercially without having to pay?
If this post was helpful please +1 or like it !

Webstrand
Yes. Boost has a very permissive license.


Not using a library means you will have to write code manually for every single platform you wish to support - and you'll have to be aware of potential bugs, security issues, and so forth on every platform. Libraries are there to take advantage of so you don't have to do all that work; frankly it's a bit silly to worry about adding an extra few KB to your installer versus adding many weeks of pain on the development side.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement