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

≡放荡痞女 提交于 2019-12-03 14:22:44

What you are using is not at all a relative path. Sure you are using the relative path syntax but not the actual meaning of what it is.

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

This path starts with a / which means root then finds it parent which return root again since root has no parent and goes on... The simplified version of this is:

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

So it will look for folder source in root which of-course doesn't exist.

What you should do is something like this (assuming your code is in project folder):

./test/file.dat

or if it is in some other folder within Project folder you can do something like this:

../test/file.dat

../ take you to the parent of your current code directory which under this case's assumption is Project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!