boost::regex example runs error throwing an instance of 'std::bad_alloc'
Jun 17, 2011 at 6:11am UTC
Here is the example -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
regex expression ("^select ([a-zA-Z]*) from ([a-zA-Z]*)" );
int
main (int argc, char *argv[])
{
std::string in;
cmatch what;
cout << "enter test string" << endl;
getline (cin, in);
if (regex_match (in.c_str (), what, expression))
{
for (int i = 0; i < what.size (); i++)
cout << "str :" << what[i].str () << endl;
}
else
{
cout << "Error Input" << endl;
}
return 0;
}
Compiling:
g++ -DBOOST_REGEX_MATCH_EXTRA exp_test.cpp -lboost_regex -o exp_test
Running
will@tp:~/rnd/boost/boost.regex$ ./exp_test
enter test string
select name from users
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
will@tp:~/rnd/boost/boost.regex$
Does anyone know why? Thank you very much.
Last edited on Jun 17, 2011 at 6:57am UTC
Topic archived. No new replies allowed.