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
.