tags:

views:

63

answers:

2

Hello,

I want to write data to a file in a directory i.e.

path_file = "/Users/aajd/2010M9/2010M9.txt";
std::ofstream outFile(path_file);

The name of the file and the path to the file is dependent of the outcome of the program. How can i accomplish this? Is it necessary that the directory already exists?

Thanks, André

+1  A: 

Yes, the folder must exist if you want to open/create a file in it.

Check this Tutorial on output through iostream

and the c++ reference

and the MSDN entries concerning directories

sum1stolemyname
+1  A: 

Yes, it is necessary for the directory to exist to create the file. You have to use system calls, such as mkdir prior to creating the ofstream object.

Didier Trosset