![](/img/trans.png)
[英]boost::regex, match_results::operator[] - Mysterious “sub += 2” line
[英]boost regex error: uninitialzed boost::match_results
运行以下内容时
bool my_compare(const std::string& string_1, const std::string& string_2)
{
const boost::regex str_re("so(m)e_(r)e(g)ex");
boost::smatch str_match;
size_t one;
uint8_t two;
size_t three;
if( boost::regex_search(string_1, str_match, str_re) ) {
one = boost::lexical_cast<size_t>( std::string(str_match[1].first, match[1].second) );
two = boost::lexical_cast<uint8_t>( std::string(str_match[2].first, match[2].second) );
three = boost::lexical_cast<size_t>( std::string(str_match[3].first, match[3].second) );
}
size_t four;
uint8_t five;
size_t six;
if( boost::regex_search(string_1, str_match, str_re) ) {
four = boost::lexical_cast<size_t>( std::string(str_match[1].first, match[1].second) );
five = boost::lexical_cast<uint8_t>( std::string(str_match[2].first, match[2].second) );
six = boost::lexical_cast<size_t>( std::string(str_match[3].first, match[3].second) );
}
return false;
}
int main()
{
my_compare(some_string1, some_string2);
return 0;
}
我收到以下错误,我不理解:
抛出'boost :: exception_detail :: clone_impl实例后调用终止
'what():错误的词法转换:无法将源类型值解释为目标
"so(m)e_(r)e(g)ex"
此正则表达式将填充捕获str_match[1]
与所述串"m"
str_match[2]
以字符串"r"
和str_match[3]
以字符串"g"
boost::lexical_cast<size_t>( std::string(str_match[1].first, match[1].second) );
这将尝试将字符串"m"
转换为size_t
类型的值,该值将失败(“ m”不是整数!),并引发异常
'what():错误的词法转换:无法将源类型值解释为目标
(顺便说一句,您不需要从一对迭代器中使用字符串构造函数跳过这些箍,子匹配项可以直接转换为字符串)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.