2010-05-13 73 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