Problem with File handling and mkdir

#include<fstream.h>
#include<conio.h>
#include<direct.h>
void main()
{
clrscr();
mkdir("H:\\Documents\\MyFolder");
ofstream ofile("H:\\Documents\\Myfile.txt");
getch();
}

Neither the mkdir command is working, nor the ofstream statement. If I write
mkdir("H:\\MyFolder");
ifstream ofile("H:\\Myfile.txt");
it works

but

mkdir("H:\\Documents\\MyFolder");
ifstream ofile("H:\\Documents\\Myfile.txt");

Does not work....The Folder Document is already created.. Why??
Last edited on
Are you sure that there is folder named Documents and that you have write permission to it?
Ye I am Sure

Please note that compiler used is Borland C++
Last edited on
Maybe you can get a useful error message by printing strerror(errno).
Last edited on
thehitmanranjan wrote:
Does not work....The Folder Document is already created.. Why??
Document or Documents? Your program is using the plural form.
I mean the Documents folder is already created...
I thought you where using ofstream but I notice you are using ifstream. Is that a mistake? If you want the program to create the file you probably want to use ofstream instead.
Last edited on
Topic archived. No new replies allowed.