#include <iostream>
#include <string>
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path p (__FILE__);
std::string new_filename = p.leaf() + ".foo";
p.remove_leaf() /= new_filename;
std::cout << p << '
';
return 0;
}
Tested with 1.37, but leaf and remove_leaf are also documented in 1.35. You'll need to test whether the last component of p is a filename first, if it might not be.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…