Opeing file from another directory.

Hello, again :)

I have problem with opening file from other directory.

If i have txt file in other directory and main.cpp in root I don't have problem with reading but if i put main.cpp in another directory i have no idea how i can read it, or how should look access path.
1
2
ifstream inmenu;
inmenu.open("files/menu.txt");

This works:

directoryprogram/main.cpp
directoryprogram/files/menu.txt

But i want open it like this:

directoryprogram/solution/main.cpp
directoryprogram/files/menu.txt


I try google it but there is only some solutions witch i really dont understand. Its possible to pick "easy way" ? :)
Thanks
closed account (Dy7SLyTq)
you need a tutorial on file paths. let me find one http://en.wikipedia.org/wiki/Path_(computing)
i don't get it, if i put there complete path way and then i copy my folder directoryprogram to another disc, it will fail again.
Search for relative paths.

Two dots means parent directory.

inmenu.open("/../files/menu.txt");
i actually try this and it dont work for me :(
inmenu.open("/../files/menu.txt");
Try it without the first '/'
example:
string filename = "../../input.txt";
Note, you can repeat the "../" as many times as required to go up more than one level.

Or to guarantee it will find the file, give the full path including drive letter,
"D:\\temp\\myfiles\\stuff.txt"

Topic archived. No new replies allowed.