#include #include using boost::filesystem::path; void replace_extension(path p, const path& extension) { std::cout << "replace_extension(" << p << "," << extension << ") = "; std::cout << p.replace_extension(extension) << '\n'; } int main() { // These cases can be acceptable if we consider that filename is empty std::cout << "\n" << "Replace extension on root-path: (arguable)\n" << "------------------------------------------\n\n"; replace_extension("/","txt"); replace_extension("C:\\","txt"); std::cout << "\n" << "Replace extension on special file-name\n" << "--------------------------------------\n\n"; replace_extension(".","txt"); replace_extension("..","txt"); replace_extension("/foo/.","txt"); replace_extension("/foo/..","txt"); std::cout << "\n" << "Replace extension on root-name\n" << "------------------------------\n\n"; replace_extension("C:","txt"); replace_extension("\\\\myserver","txt"); getchar(); return 0; }