【发布时间】:2014-03-04 18:35:33
【问题描述】:
运行以下时
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(): bad lexical cast: 源类型值不能被解释为目标
【问题讨论】:
-
str_match和match应该是一样的吗?它有助于发布可编译的代码。 -
match[x] 由正则表达式生成。 str_match 是用于结果的对象
-
显示的代码没有初始化甚至没有声明任何名为
match的东西。