gpt4 book ai didi

c++ - Boost::regex_iterator 构造函数失败但 make_regex_iterator 函数成功

转载 作者:行者123 更新时间:2023-11-28 03:48:48 25 4
gpt4 key购买 nike

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 库在 Linux 上以默认的非递归模式编译。

编辑:也试过

regex_it = boost::cregex_iterator(line.data(), line.data()+line.size(), re);

同样的问题。

最佳答案

尝试使用 regex_iterator<char const*>而不是 regex_iterator<std::string::const_iterator> . (此外,您调用 make_regex_iterator 的方式在很大程度上不必要地冗长。)

假设linestd::string ,试试这个:

regex_it = boost::make_regex_iterator(line.c_str(), re);

或者这个:

regex_it = boost::cregex_iterator(line.data(), line.data() + line.size(), re);

关于c++ - Boost::regex_iterator 构造函数失败但 make_regex_iterator 函数成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6350638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com