整数ペアの文字列を数値に解析したいと思います。私はこのコードを使用します:
#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"
gcc4.7.2によってコンパイルされたboost1.52で得たもの:
found: "2":"2"
found: "4":"4"
found: "6":"6"
ブースト1.52clang3.2:
found: "":"2"
found: "":"4"
found: "":"6"
私のコードの何が問題になっていますか?