Hey all,

I am a relatively new programmer and am trying to use Boost regex for my program. My code is:

#include <boost\boost\regex.hpp>

using namespace std;

double scrape( string base, string match )
{
       boost::regex re(match);
       boost::smatch matches;
       string::const_iterator start;
       
       start = base.begin();
       
       while( boost::regex_search( start, base.end(), matches, re ) )
       {
              string value( matches[1].first, matches[1].second );
              double rvalue = atof(value.c_str());
              return rvalue;
       }      
}

This basically takes in my string (called base) and an expression to match (called match) and tries to return a double (I am searching for numbers). The error I am getting is with the regex_search function which states:

16 C:\Users\Devin\Desktop\Dev Programs\C++\ssearch\Scrape.h no matching function for call to `regex_search(const char&, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::smatch&, boost::regex&)'

Any help would be greatly appreciated.

Thanks.

Anybody please?

#include <boost/regex.hpp>
#include <string>
#include <boost/lexical_cast.hpp>

using namespace std;

double scrape( const std::string& base, const std::string& match )
{
    boost::regex re(match);
    boost::smatch matches;

    // while( boost::regex_search( start, base.end(), matches, re ) )
    if( boost::regex_search( base, matches, re ) )
    {
        std::string value( matches[1].first, matches[1].second );
        return boost::lexical_cast<double>(value) ;
    }
    else return 0.0 ;
}
commented: well spotted +3

Thank you very much for the reply. It compiles fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.