0
votes

I have read some amount of documentation, and I am more familiar with the current version being shipped with VS2010. But for now I am stuck with ubuntu 8.04, and boost 1.34 and am getting some weird sort of error. Can anybody tell what I am doing wrong. Here is the man page for regex_search boost v1.34

Here is what I am doing in my code :

std::string sLine;
getline(dataFile, sLine);
boost::match_results<std::string::const_iterator> lineSmatch; 
boost::match_flag_type regFlags = boost::match_default;    
boost::regex finalRegex(linePattern);

boost::regex_search(sLine.begin(), sLine.end(), lineSmatch, finalRegex, regFlags);

Here is the compilation error:

error: no matching function for call to 'regex_search(__gnu_cxx::__normal_iterator, std::allocator > >, __gnu_cxx::__normal_iterator, std::allocator > >, boost::match_results<__gnu_cxx::__normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >&, boost::regex&, boost::regex_constants::match_flag_type&)'

2

2 Answers

1
votes

If you are going to apply regex_search to sLine itself instead of iterator range, as Howard answered, you can use sLine instead of begin() and end().
For example:

boost::regex_search(sLine, lineSmatch, finalRegex, regFlags);

If you have to give iterator range to regex_search, since the type argument for match_results is const_iterator, the first and second arguments for regex_search need to be const_iterator too.
For example:

std::string::const_iterator b = sLine.begin(), e = sLine.end();
boost::regex_search(b, e, lineSmatch, finalRegex, regFlags);

Hope this helps

0
votes

Can't help you specifically with ubuntu 8.04, and boost 1.34. However the following compiles for me on libc++ which implements C++11. Perhaps it is close enough to your environment to tell you what is wrong.

#include <regex>
#include <fstream>

int main()
{
    std::ifstream dataFile;
    std::string sLine, linePattern;
    getline(dataFile, sLine);
    std::match_results<std::string::const_iterator> lineSmatch; 
    std::regex_constants::match_flag_type regFlags = 
                                        std::regex_constants::match_default;    
    std::regex finalRegex(linePattern);

    std::regex_search(sLine, lineSmatch, finalRegex, regFlags);
}