KH17
KH17

Reputation: 111

Error trying to convert from string to int using boost regex match in c++

I am trying to convert the matched string into a int using regex/boost. I used this C++ to convert Boost Regex match result to other format as a reference. However when I tried I got expected primary-expression before ‘int’ and Symbol 'lexical_cast' could not be resolved error.

this is my code:

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

using namespace std;
using namespace boost;


int main(){
    string a = "123";
    boost::regex e("123");
    boost::smatch match;

    if (boost::regex_search(a, match, e))
        {
            int number = boost::lexical_cast<int>(match[0]);
            cout << number << endl;
         }
    return 0;
}

why am I getting these errors?

Upvotes: 2

Views: 415

Answers (1)

Richard Hodges
Richard Hodges

Reputation: 69892

you forgot this line:

#include <boost/lexical_cast.hpp>

Upvotes: 2

Related Questions