Jump to content
  • Advertisement
Sign in to follow this  
coderWalker

Writing Files in Directorys

This topic is 2894 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 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!