tags:

views:

253

answers:

2

Hello everyone,

I am working off a project in visual studio 2008 and my program outputs a whole bunch of .txt files that i use to check if my program is running as it should. At first i was only outputting a few files, but now i'm outputting more and more and the input files and output files are getting mixed up and it is becomming hard for me to quickly pinpoint which file i need to read and check.

My question is this:

How do get my program to create a new folder inside the working folder (the development folder in which you place files to be read into the program simply by using the most simple version of .open() ), rename them, and output files only to them without manual hard-coding a path?

Thanks,

-Faken

Edit: sorry, forgot to say I'm working on a windows platform...

A: 
#include <windows.h>

CreateDirectory (char *DirName, SECURITY_ATTRIBUTES Attribs);

Salu2.

Miguel Angel
And how do i get my program to save things to that folder using the simple ofstream?
Faken
you could use c++ standar library: http://www.cplusplus.com/reference/iostream/ofstream/
Miguel Angel
also you could look msdn library for working on a windows platform: http://msdn.microsoft.com/en-us/library/aa364407(VS.85).aspx
Miguel Angel
After creating the directory, create an ostream with "folder\\filename" and you should be all set :)
Billy ONeal
+5  A: 

Consider using boost::filesystem as it provides a great deal of portable file-system functionality.

#include<string>
#include<boost/filesystem/operations.hpp>

int main()
{
   using boost::filesystem;
   std::string dir_name = "c:\\my_dir";
   create_directory(path(dir_name));
   return 0;
}
Beh Tou Cheh