954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

make directory

How can i create a directory in c++ other than writing

system ("md directory");
xfruan
Newbie Poster
12 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Linux

#include <sys/stat.h>

mkdir (const char *path, mode_t mode);


in this case mode = O_CREAT. Function returns an int. Lookup "man mkdir", if memory serves me correctly for more details.

Windows

#include <windows.h>

CreateDirectory (char *DirName, SECURITY_ATTRIBUTES Attribs);


If the function succeeds returns non-zero otherwise NULL.

Tight_Coder_Ex
Posting Whiz in Training
215 posts since Feb 2005
Reputation Points: 47
Solved Threads: 17
 

Problem is when i tried both ways in Visual C++, neither of the methods worked, in both cases, the compiler told me there is no such an include file. Instead, i found a function "mkdir (const char*)" in the include file called "direct.h".

xfruan
Newbie Poster
12 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

If you not too concerned about the bells and whistles that go along with 95/98/XP then mkdir will work just fine.

If you are creating projects in VC++ 6.0 with the wizzard and "stdafx.h" is already included you don't have to worry about because it's already in there.

Tight_Coder_Ex
Posting Whiz in Training
215 posts since Feb 2005
Reputation Points: 47
Solved Threads: 17
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You