2013-07-26 24 views
0

我只是無法獲得regex_match函數來查找不區分大小寫的匹配。儘管boost::xpressive::regex_constants::icasedefined我用鑄造(所以沒有歧義,以xpressive中的icase方法),我得到一個編譯錯誤(VS2010):與Boost不區分大小寫匹配Xpressive

錯誤C2440:「類型轉換」:不能從轉換'常量的boost :: xpressive中::詳細:: modifier_op' 到 '的boost :: xpressive中:: regex_constants :: match_flag_type'

一些代碼來重現:

#include <stdio.h> 
#include <boost/xpressive/xpressive.hpp> 

int main(){ 
    std::string str("FOO"); 
    boost::xpressive::sregex re = boost::xpressive::sregex_compiler().compile("foo"); 
    bool result = regex_match(str,re,(boost::xpressive::regex_constants::match_flag_type)boost::xpressive::regex_constants::icase); 
    if(result){ 
     std::cout << "Match!"; 
    }else{ 
     std::cout << "No match!"; 
    } 
    return 0; 
} 

你知道是什麼問題可能?

回答

2

嘗試使用

boost::xpressive::sregex re = boost::xpressive::sregex_compiler(). 
compile("foo", boost::xpressive::icase); 

syntax_options_type(即boost::xpressive::regex_constants::icase_)不match_flag_type(3論據regex_match應該有這個類型)。

+0

謝謝,這對我有用! – muffel

+0

對。並且在將來,聽聽編譯器告訴你什麼。事實上,你必須將'icase'標誌轉換爲'match_flag_type'才能進行編譯,這應該會引發你錯誤的做法。然後閱讀文檔。 :-) –

相關問題