I want to write data to a file in a directory ie
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é
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.