tags:

views:

40

answers:

1

This is my code:

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

This is what compiler says:

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)

The link to the library: http://www.boost.org/doc/libs/1_43_0/doc/html/boost/algorithm/replace_regex_copy.html

Could anyone please help? Thanks!

ps. Boost library is in place, since other functions from it work fine.

+2  A: 

replace_regex_copy takes a boost::regex as its second argument, not a std::string.

There is an explicit conversion from std::string to boost::regex, but no implicit conversion exists, so you can fix your code by changing it to...

string f(const string& s) {
      using namespace boost::algorithm;
      return replace_regex_copy(s, boost::regex("\\w"), "?");
}
Joe Gauterin
Thank you very much!
Vincenzo