public member function
<regex>

std::match_results::end

const_iterator begin() const;
返回指向末尾的迭代器
返回一個迭代器,指向 match_results 物件中超出末尾的匹配項。 與 match_results::begin 一起,這些函式描述了一個範圍,該範圍包含 match_results 物件中的所有匹配項。

如果 match_results 物件是 空的(即,表示式不匹配),則返回的值為endbegin 返回的值相同,表示一個空範圍,不應被取消引用。

如果 match_results 物件未 就緒,則此函式返回的值可能與 begin 的值無關,因此不應用來指定範圍。 也不應取消引用。

引數



返回值

一個迭代器,指向 match_results 物件中匹配序列中 超出末尾位置的 sub_match

成員型別const_iterator(與成員型別相同iterator)是一個 前向迭代器 型別。
match_results 物件中包含的匹配項始終為常量。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// match_results::begin/end
// - using smatch, a standard alias of match_results<string::iterator>
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  std::string s ("subject");
  std::smatch m;
  std::regex e ("(sub)(.*)");

  std::regex_match ( s, m, e );

  std::cout << "matches:" << std::endl;
  for (std::smatch::iterator it = m.begin(); it!=m.end(); ++it) {
	std::cout << *it << std::endl;
  }
  return 0;
}

輸出
matches:
subject
sub
ject



另見