I'm a newbie. I wanted to know how to create a folder using c++. After creating a folder I would access a function which will give me a set of *.txt files which needs to be outputted to the newly created folder.
Here, It does print the files (Example: Time step-1, Time step-2,.........Time step n) . I want to create a folder named ftcs (for example) first and then I need to print the files inside the folder what I created.
There are two different directories to consider. One is the directory where the executable is located. The other is the current working directory (cwd).
Here's a short program which should display both. Depending upon your system, these may or may not be the same.
But now I would need to place my files inside the directory which i created.
How would I change the directory where my files are to be printed out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <direct.h> // for _mkdir
int counter = 0;
while(counter < 10)
oss << "ABCDEF " << counter;
return 0; // main returns 0 even if it's not explicit,
// so you might as well make this clear!
Filename can contain a path component. Path can be either relative or absolute. The system actually concatenates cwd (an absolute path) with a filename that has either relative or no path in order to create an absolute path.
If a system library provides getcwd, it probably has setcwd as well.
[code]// when getcwd returns "C:/foo"
myfile.open("bar.txt"); // same as "C:/foo/bar.txt"
myfile.open("gaz/bar.txt"); // same as "C:/foo/gaz/bar.txt"
myfile.open("../Users/bar.txt"); // same as "C:/Users/bar.txt"