这是我的代码:
#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_copy
将 boost::regex
作为其第二个参数,而不是 std::string
。
存在从 std::string
到 boost::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/