I'm trying to learn how to use the regex library in c++11. On ubuntu 13.10 I'm trying to compile the following example from cplusplus.com:
// regex_replace example
#include <iostream>
#include <string>
#include <regex>
#include <iterator>
int main ()
{
std::string s ("there is a subsequence in the string\n");
std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
// using string/c-string (3) version:
std::cout << std::regex_replace (s,e,"sub-$2");
// using range/c-string (6) version:
std::string result;
std::regex_replace (std::back_inserter(result), s.begin(), s.end(), e, "$2");
std::cout << result;
// with flags:
std::cout << std::regex_replace (s,e,"$1 and $2",std::regex_constants::format_no_copy);
std::cout << std::endl;
return 0;
}
With the command:
$ g++ -std=c++11 -o file file.cc
I get the following output:
file.cc:13:48: error: no matching function for call to ‘regex_replace(std::string&, std::regex&, const char [7])’
What am I doing wrong?! There's not much hair left on my head... Thanks in advance