c++ - 如何使用 boost::algorithm 库中的 replace_regex_copy()?

标签 c++ boost

这是我的代码:

#include <string>
#include <boost/algorithm/string/regex.hpp>
string f(const string& s) {
      using namespace boost::algorithm;
      return replace_regex_copy(s, "\\w", "?");
}

这是编译器说的:

no matching function for call to ‘replace_regex_copy(const
std::basic_string<char, std::char_traits<char>,
std::allocator<char> >&, std::string, std::string)

图书馆链接:http://www.boost.org/doc/libs/1_43_0/doc/html/boost/algorithm/replace_regex_copy.html

有人可以帮忙吗?谢谢!

附言。 Boost 库已就位,因为它的其他功能可以正常工作。

最佳答案

replace_regex_copyboost::regex 作为其第二个参数,而不是 std::string

存在从 std::stringboost::regex显式转换,但不存在隐式转换,因此您可以修复通过将代码更改为...

string f(const string& s) {
      using namespace boost::algorithm;
      return replace_regex_copy(s, boost::regex("\\w"), "?");
}

关于c++ - 如何使用 boost::algorithm 库中的 replace_regex_copy()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2825165/

相关文章:

C++ 命名空间 : using without owning

c++ - 如何为 boost::program_options 的位置选项添加描述?

c++ - boost 属性树 : Where have my escape sequences gone in JSON String?

c++ - 模板类中 boost::unordered_map 中的 boost::tuple 出现问题

c++ - 使用 Boost ProgramOptions 处理 2 级命令的最佳方式

c++ - c++ 阶乘程序中的递归

c++ - basic_string::_S_construct null 无效

c++ - 制作图形用户界面编辑器

c++ - 该标准是否定义了共同基础?

c++ - Boost套接字在断开连接时不会抛出EOF