mkdir c++ function

If you want to write cross-platform code, you can use boost::filesystem routines

#include <boost/filesystem.hpp>
boost::filesystem::create_directory("dirname");

This does add a library dependency but chances are you are going to use other filesystem routines as well and boost::filesystem has some great interfaces for that.

If you only need to make a new directory and if you are only going to use VS 2008, you can use _mkdir() as others have noted.


It's deprecated, but the ISO C++ conformant _mkdir() replaced it, so use that version. All you need to call it is the directory name, its sole argument:

#include <direct.h>

void foo()
{
  _mkdir("C:\\hello"); // Notice the double backslash, since backslashes 
                       // need to be escaped
}

Here is the prototype from MSDN:

int _mkdir( const char *dirname );