As the name implies the Boost.Filesystem[1] library provides functions to work with the file system.

Path Manipulation Example

This example shows how to use boost::filesystem::path and some of its operations. The full example is available from our GitHub repository: BoostTutorials/Filesystem/Path1.

 File: main.cpp
#include <boost/filesystem/path.hpp>
#include <iostream>

int main(int argc, char* argv[])
    // Simple filename construction
    boost::filesystem::path path1("file1.txt");
    std::cout << "path1: " << path1 << std::endl;

    // Concatenation using the preferred directory
    // separator
    boost::filesystem::path path2("dir1");
    path2 /= path1;
    std::cout << "path2: " << path2 << std::endl;

On Windows this will produce the following output.

 Console output
path1: "file1.txt"
path2: "dir1\file1.txt"
Press any key to continue . . .


  1. Boost.Filesystem: official documentation (