+ 5
how to open a specific file location?
rather then the same folder as the program.
2 Answers
+ 2
On Windows, you can
ifstream myFile;
myFile.open("C:\\Path to\\MyFile.txt");
Note the double backslashes avoiding the backslash being interpreted as an escape character (as in e.g. "\n"). I think you can also use forward slashes on Windows.
In Linux, I guess you can specify an absolute path by starting with a /:
ifstream myFile;
myFile.open("/etc/Path to/MyFile.txt");
To give paths relative to your executable, you can move one directory up with "..":
ifstream myFile;
myFile.open("..\..\MyFileTwoDirectoriesAboveExe.txt");
+ 3
specify the absolute path of the file you want to work with.
if you want to open a folder in a new window send a command using
system("start c:\yourFolder");
in your C++ program.