I am trying to use code that I wrote on another computer that breaks a string into tokens. This code compiles fine. The code also works as intended on some other computers. I managed to reduce the code to the following:
#include <string>
#include <boost/regex.hpp>
typedef std::vector<std::string> token_t ;
token_t generate_tokens(std::string raw_input){
boost::regex re_splitter("\\s+");
boost::sregex_token_iterator iter(raw_input.begin(), raw_input.end(), re_splitter, -1);
boost::sregex_token_iterator j;
token_t token_vector;
unsigned int count = 0;
while(iter != j)
{
token_vector.push_back(*iter);
std::cout << *iter++ << std::endl;
++count;
}
return token_vector;
}
int main(){
std::string in;
int amount = -1;
std::cout << "action: ";
std::getline(std::cin, in);
boost::regex EXPR("^test \\d*(\\.\\d{1,2})?$");
bool format_matches = boost::regex_match(in, EXPR);
token_t tokens = generate_tokens(in);
if(format_matches){
amount = atoi(tokens.at(1).c_str());
}
std::cout << "amount: " << amount << "\n";
return 0;
}
This compiles without errors or warnings, using: g++ -Wall test.cpp -lboost_regex
but when used at run time that provides input test 100, the program fails.
action: test 100
a.out: /usr/local/include/boost/smart_ptr/shared_ptr.hpp: 412: typename boost :: detail :: shared_ptr_traits :: reference boost :: shared_ptr :: operator * () const [with T = boost :: regex_traits_wrapper โ]: the statement `px! = 0 'failed.
Interrupted
, . ? !