案例1:
const char* infile = "c:\\windows\\winhelp.exe";
std::string newfile(infile);
std::size_t found = newfile.find_last_of("/\\");
if (found != std::string::npos)
{
std::string dir = newfile.substr(0, found);
std::string filename = newfile.substr(found + 1);
std::cout << "dir:" << dir << std::endl;
std::cout << "filename:" << filename << std::endl;
newfile = dir + "\\rect_" + filename;
}
最终newfile="c:\\windows\\rect_winhelp.exe"
案例2:
const char* infile = "c:\\windows\\winhelp.exe";
std::string dstPath(infile);
dstPath.insert(dstPath.size() - 4, "2dst");
最终dstPath="c:\\windows\\winhelp2dst.exe"