#include#include int main() { boost::filesystem::path p("/home/user/documents/file.txt"); boost::filesystem::path parent = p.branch_path(); std::cout << parent << std::endl; return 0; }
#includeIn this example, we create a path object representing the directory "/home/user/documents/". We then call the branch_path() function to get the parent directory of the directory, which is "/home/user" and print it to the console. Package Library: Boost.Filesystem is part of the Boost C++ Libraries.#include int main() { boost::filesystem::path p("/home/user/documents/"); boost::filesystem::path parent = p.branch_path(); std::cout << parent << std::endl; return 0; }