#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream fo("output/folder1/data/today/log.txt");
fo << "Hello world\n";
fo.close();
return 0;
}
I need to output some log data to some files with variable names. However, ofstream does not create directories along the way, if the path to the file doesn't exist, ofstream writes to nowhere!
What can I do to automatically create folders along a file path? The system is Ubuntu only.