嗯...我以为我理解了正则表达式,也以为我理解了迭代器,但是C++11的正则表达式实现却让我感到困惑...
有一个领域我不理解:阅读关于regex token iterators的内容,我看到了下面这个样例代码:
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main()
{
std::string text = "Quick brown fox.";
// tokenization (non-matched fragments)
// Note that regex is matched only two times: when the third value is obtained
// the iterator is a suffix iterator.
std::regex ws_re("\\s+"); // whitespace
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
...
}
我不理解以下输出的含义:
Quick
brown
fox.
上面的std::copy()函数正在创建。我没有看到循环,所以我不知道迭代是如何发生的。换句话说,多行输出是如何生成的?