2012-09-28 24 views

回答

2

我敢肯定你想有

string text(match[1]); 
// convert match[2] to integer 

代替,如match[0]是整個匹配的東西(ABC123這裏),這樣子匹配索引從1開始

由於轉換爲整數部分,便於使用:

string s = "abc123"; 
boost::regex expr("(\\s+)(\\d+)"); 
boost::smatch match; 
if(boost::regex_search(s, match, expr)) { 
    string text(match[1]); 
    int num = boost::lexical_cast<int>(match[2]); 
} 
相關問題