How to create a Directory in C++?

R

Rajesh N Thipse

Hi,
Files can be created using _creat.
Similarly, is there a function to create a directory?

~Rajesh
 
V

Victor Bazarov

Rajesh said:
Files can be created using _creat.

Really? I don't know such function in the Standard library.
Similarly, is there a function to create a directory?

Similarly, no. Check the programming manual for your OS.

V
 
R

Rajesh N Thipse

Victor Bazarov said:
Really? I don't know such function in the Standard library.
--------------------
In VC++, the following piece of code generates "temp" file
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

void main( void )
{
int fh = _creat( "temp", _S_IREAD | _S_IWRITE );
if( fh == -1 )
perror( "Couldn't create data file" );
else
{
printf( "Created data file.\n" );
_close( fh );
}
}

Output

Created data file.
--------------------
Similarly, no. Check the programming manual for your OS.
--------------------
However, whether one uses _creat for creating a file or some other
function to do so is immaterial. The real question of creating a
directory remains unanswered.
I've checked programming manual, but didn't get much of help. Also
if I go for a OS specific function there can be an issue of
portability later.
--------------------
[A-Za-z ]+
 
R

Rajesh N Thipse

Hi,
Files can be created using _creat.
Similarly, is there a function to create a directory?

~Rajesh


I am able to do what I wanted. Thanks for all the replies and suggestions.
~Rajesh
 
J

Jon Bell

[...]

But that is not standard C++. It uses Windows-specific functions. Here's
what I got when I tried to compile it under Mac OS X:

[Jon-Bells-Computer:~/Documents/c++] jtbell% c++ create.cpp
create.cpp:1:16: io.h: No such file or directory
create.cpp:8: error: `main' must return `int'
create.cpp: In function `int main(...)':
create.cpp:9: error: `_S_IREAD' undeclared (first use this function)
create.cpp:9: error: (Each undeclared identifier is reported only once for
each
function it appears in.)
create.cpp:9: error: `_S_IWRITE' undeclared (first use this function)
create.cpp:9: error: `_creat' undeclared (first use this function)
create.cpp:15: error: `_close' undeclared (first use this function)
 
S

Stephan Br?nnimann

I am able to do what I wanted. Thanks for all the replies and suggestions.
~Rajesh

This is the kind of people that we all wish to have as posters
to this newsgroup!

Stephan :-O
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top