I have a certain boost::filesystem::path in hand and I'd like to append a string (or path) to it.
boost::filesystem::path p("c:\\dir"); p.append(".foo"); // should result in p pointing to c:\dir.foo The only overload boost::filesystem::path has of append wants two InputIterators.
My solution so far is to do the following:
boost::filesystem::path p2(std::string(p.string()).append(".foo")); Am I missing something?
boost::filesystem::path is the central class in Boost. Filesystem for representing and processing paths. Definitions can be found in the namespace boost::filesystem and in the header file boost/filesystem. hpp . Paths can be built by passing a string to the constructor of boost::filesystem::path (see Example 35.1).
If it's really just the file name extension you want to change then you are probably better off writing:
p.replace_extension(".foo"); for most other file path operations you can use the operators /= and / allowing to concatenate parts of a name. For instance
boost::filesystem::path p("c:\\dir"); p /= "subdir"; will refer to c:\dir\subdir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With