My current working directory is located at /home/myuser/program, I created a boost::filesystem::path object pointing to it. I appended /../somedir so it becomes /home/myuser/program/../somedir. But I need to get its resolved absolute path, which would be /home/myuser/somedir.
I have been trying for long time and I do not find any method in their reference to do this. There is a method called make_absolute, which seems to be supposed to do what I expect, but I have to give it a “root” path argument. Which should it be? do I really need to do this to get the real absolute path? Is there any other way?
You say you want an absolute path, but your example shows that you already have an absolute path. The process of removing the
..components of a path is known as canonicalization. For that, you should callcanonical. It happens to also perform the task ofabsolute, so you don’t need to callabsoluteormake_absolutefirst. Themake_absolutefunction requires a base path; you can pass itcurrent_path()if you don’t have anything better.