2013-07-26 26 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'才能进行编译,这应该会引发你错误的做法。然后阅读文档。 :-) –

相关问题