3 回答

TA貢獻(xiàn)1784條經(jīng)驗 獲得超7個贊
為什么不實施自己的替換?
void myReplace(std::string& str,
const std::string& oldStr,
const std::string& newStr)
{
std::string::size_type pos = 0u;
while((pos = str.find(oldStr, pos)) != std::string::npos){
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
}

TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊
#include <boost/algorithm/string.hpp> // include Boost, a C++ library
...
std::string target("Would you like a foo of chocolate. Two foos of chocolate?");
boost::replace_all(target, "foo", "bar");
這是關(guān)于replace_all 的官方文檔。
- 3 回答
- 0 關(guān)注
- 347 瀏覽
添加回答
舉報