C++ string.replace的使用

//下面是一个检查一个字符串中是否有'.'的函数,该函数将找到的'.'转化为'_'。
inline void checkName(string& name)
{
std::string::size_type startpos = 0;
while (startpos!= std::string::npos)
{
    startpos = name.find('.');   //找到'.'的位置
    if( startpos != std::string::npos ) //std::string::npos表示没有找到该字符
    {
      name.replace(startpos,1,"_"); //实施替换,注意后面一定要用""引起来,表示字符串
    }
}
}
原文地址:https://www.cnblogs.com/blogpro/p/11339042.html