#include#include namespace fs = boost::filesystem; int main() { fs::path path("C:\\Users\\username\\Documents\\file.txt"); std::cout << path.parent_path(); // Output: C:\Users\username\Documents return 0; }
#includeThis example shows how to traverse up the directory structure using the `parent_path()` function. We start with the file path and iterate through each component of the path until we reach the root directory. This can be useful if we want to perform operations in the parent directories recursively. Both of these examples use the Boost.Filesystem library, which is included in the Boost C++ Libraries package.#include namespace fs = boost::filesystem; int main() { fs::path path("C:\\Users\\username\\Documents\\file.txt"); for (auto it = path.begin(); it != path.end(); ++it) { std::cout << *it << '\n'; } return 0; }