Boost :: regex_iterator构造函数失败,但make_regex_iterator函数成功

问题描述

||
std::string line;
抛出
std::runtime_error what():  Memory exhausted
regex_it =  boost::sregex_iterator(line.begin(),line.end(),re);
这工作正常:
regex_it = boost::make_regex_iterator(line,re);
有谁知道是什么导致性能差异? boost :: regex lib是在Linux上以认非递归模式编译的。 编辑: 也试过了 regex_it = boost :: cregex_iterator(line.data(),line.data()+ line.size(),re); 同样的问题。     

解决方法

        尝试使用
regex_iterator<char const*>
而不是
regex_iterator<std::string::const_iterator>
。 (此外,您呼叫ѭ6的方式在很大程度上不必要地冗长。) 假设
line
std::string
,请尝试以下操作:
regex_it = boost::make_regex_iterator(line.c_str(),re);
或这个:
regex_it = boost::cregex_iterator(line.data(),line.data() + line.size(),re);