How to open a file with relative path in C++?

Viewed 31232

I am writing test cases right now and I created some test files which I try to read. The absolute path is:

/home/user/code/Project/source/Project/components/Project/test/file.dat

but testing with an absolute path is bad for obvious reasons. So I try to convert the absolute path into a relative one and I don't know why it doesn't work. I created a file with the relative path

findme.dat

and I found it in

/home/user/code/Project/build/source/Project/components/Project/test/findme.dat

so I created the relative path

/../../../../../../source/Project/components/Project/test/file.dat

but the file is not open and not associated with the is object, std::ifstream is (path);, and the is.is_open() function returns fulse.

Can you help me?

1 Answers
Related