C++ 如何使用Boost正则表达式替换方法?

C++ 如何使用Boost正则表达式替换方法?,c++,boost,boost-regex,C++,Boost,Boost Regex,我有以下变量: boost::regex re //regular expression to use std::string stringToChange //replace this string std::string newValue //new value that is going to replace the stringToChange depending on the regex. 我只想替换第一次出现的它而已 谢谢各位 编辑:我发现: boost::regex_replac

我有以下变量:

boost::regex re //regular expression to use
std::string stringToChange //replace this string
std::string newValue //new value that is going to replace the stringToChange depending on the regex.
我只想替换第一次出现的它而已

谢谢各位

编辑:我发现:

boost::regex_replace(stringToChange, re, boost::format_first_only);

但是它说该函数不存在,我猜目前参数不正确。

下面是一个基本用法的示例:

#include <iostream>
#include <string>
#include <boost/regex.hpp>

int main(){
  std::string str = "hellooooooooo";
  std::string newtext = "o Bob";
  boost::regex re("ooooooooo");
  std::cout << str << std::endl;

  std::string result = boost::regex_replace(str, re, newtext);
  std::cout << result << std::endl;
}
#包括
#包括
#包括
int main(){
std::string str=“hellooo”;
std::string newtext=“o Bob”;
boost::regex re(“ooooooo”);
标准::cout