# Writing Files in Directorys

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

## Recommended Posts

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; }

##### Share on other sites
Have a look at boost::filesystem, it should do exactly what you need and quite portably.

##### Share on other sites
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?

##### Share on other sites
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.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632565
• Total Posts
3007106

×