Click to See Complete Forum and Search --> : make directory


umeshban
March 20th, 2003, 04:27 AM
Hello All ,
I was wondering how i could write to a new directory using "ofstream " .

eg., ..\\twist\\temp.txt where twist is the directory to be created and "temp.txt" is created using ofstream.

Also does anybody have some info on using absolute
and relative paths in c++,would be quite a help.

Peace 2 all ,
Umesh

stober
March 20th, 2003, 08:11 AM
as far as I know you can't use fstream to create a directory. you have to use other functions, e.g. mkdir() or CreateDirectory() (windows OS).

umeshban
March 20th, 2003, 08:16 AM
hi Stober,
Nope,I need my programe to work in other OS too,so Can't use the stuff u sujjested.
Thanks
Umesh

PaulWendt
March 20th, 2003, 08:31 AM
You will have to either use portable functions or #ifdef for the
OS-specific code. I think that mkdir() should be available almost
everywhere. If it's not available on a system, you'll have to do
OS-specific code then.

--Paul

brapler
March 22nd, 2003, 08:25 AM
why don't you use mkdir?

under windows :
#include <direct.h>
_mkdir(path) ;
under unix:
#include <sys/stat.h>
mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);

umeshban
March 22nd, 2003, 12:17 PM
brapler Thanks a lot ,
dont worry about the lingo it was clear enough.

have a lovely weekend,
Regards,
Umesh