我想将一串整数对解析为数字。我使用这段代码:
#include <iostream>
#include <boost/regex.hpp>
int main()
{
boost::regex reg( "(\\d+):(\\d+)" );
std::string test = "1:2 3:4 5:6";
boost::sregex_token_iterator end;
for( boost::sregex_token_iterator i( test.begin(), test.end(), reg ); i != end; ++i ) {
boost::smatch what;
if( boost::regex_match( i->str(), what, reg ) )
std::cout << "found: \"" << what[1].str() << "\":\"" << what[2].str() << "\"" << std::endl;
}
return 0;
}
预期输出:
found: "1":"2"
found: "3":"4"
found: "5":"6"
我用 gcc 4.7.2 编译的 boost 1.52 得到了什么:
found: "2":"2"
found: "4":"4"
found: "6":"6"
提升 1.52 铿锵 3.2:
found: "":"2"
found: "":"4"
found: "":"6"
我的代码有什么问题?