簡體   English   中英

Boost::regex_iterator 構造函數失敗但 make_regex_iterator function 成功

[英]Boost::regex_iterator constructor fails but make_regex_iterator function succeeds

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM