string 子字符串替换函数 void string_replace( std::string &strBig, const std::string &strsrc, const std::string &strdst ) { std::string::size_type pos = 0; std::string::size_type srclen = strsrc.size(); std::string::size_type dstlen = strdst.size(); while( (pos=strBig.find(strsrc, pos)) != std::string::npos ) { strBig.replace( pos, srclen, strdst ); pos += dstlen; } } 能够将一个string中的子字符串替换成另外一个子字符串。其中用到了,stirng::replace 函数,第一个参数是开始替换的位置,第二个参数是替换字符的个数,第三个参数是新的子字符串。