2

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?

Community
  • 1
  • 1
KH17
  • 111
  • 11

1 Answers1

2

you forgot this line:

#include <boost/lexical_cast.hpp>
Richard Hodges
  • 68,278
  • 7
  • 90
  • 142
  • wow. Thanks. i knew it was something silly. If I want to convert to double/float all I have to do is change the `` to ``, `` right? – KH17 May 20 '15 at 14:52
  • Yes, that'll do it. Any type for which an `operator>>(std::ostream&, TYPE&)` is defined should work. – Richard Hodges May 20 '15 at 14:54