2010-05-13 74 views
1

这是我的代码:如何使用boost :: algorithm库中的replace_regex_copy()?

#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

谁能请帮助?谢谢!

ps。 Boost库已经到位,因为它的其他功能工作正常。

回答

3

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"), "?"); 
} 
+0

非常感谢您! – yegor256 2010-05-13 09:31:36