Я пытаюсь использовать некоторый код, написанный на другом компьютере, который разбивает строку на токены.Этот код компилируется нормально.Код также работает так, как задумано на некоторых других компьютерах.Мне удалось сократить код до следующего:
#include <string>
#include <boost/regex.hpp>
typedef std::vector<std::string> token_t ;
token_t generate_tokens(std::string raw_input){
//this function breaks a input string into tokens. So test 100 goes to 2 tokens "test" and "100".
boost::regex re_splitter("\\s+"); //this uses the regex \s+ to find whitespace. The + finds one or more whitespace characters.
boost::sregex_token_iterator iter(raw_input.begin(), raw_input.end(), re_splitter, -1);
//this breaks the string using the regex re_splitter to split into tokens when that is found.
boost::sregex_token_iterator j; //This is actually in the Boost examples, j is the equivalent of end. Yes this did also seem weird to me at first...
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;
}
Компилируется без ошибок или предупреждений, используя: g++ -Wall test.cpp -lboost_regex
, но при использовании во время выполнения с вводом test 100
программа завершается ошибкой.
действие: тест 100
a.out: /usr/local/include/boost/smart_ptr/shared_ptr.hpp:412: повышение имени пользователя :: detail :: shared_ptr_traits :: повышение ссылки:: shared_ptr :: operator * () const [с T = boost :: regex_traits_wrapper>>]: сбой утверждения «px! = 0».
Прервано
I'mполностью потерялся относительно того, что здесь происходит.Это ошибка в моем коде или в библиотеке?Любой совет по отладке это очень ценится!