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

system ("md directory");

Recommended Answers

All 3 Replies

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.

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".

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 <windows.h> because it's already in there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.