How to read/write file in separate folder?

Question as above: I want for my program to write and read to and from files that are in completely different folder: example giving while program is in C:\Cpp\Project\..., to use file in C:\Data\Programming\Cpp\...
Thanks in advance :)
Use absolute or relative path to destination file:

ofstream ofs("C:\\Data\\Programming\\Cpp\\out.txt");

or, if your current folder is C:\Cpp\Project, you can refer to the destination as
ofstream ofs("..\\..\\Data\\Programming\\Cpp\\out.txt");
Last edited on
One more question. If the output folder doesn't exist on the first run, will it be created?
No.
Working with directories is platform-dependent, and programming language cannot handle such a situation automatically.
Topic archived. No new replies allowed.