public member function
<regex>

std::sub_match::str

string_type str() const;
返回字串
返回包含 sub_match 物件引用的內容的副本的字串。

引數



返回值

一個 string,包含 sub_match 引用的內容。

string_type是一個成員型別,被定義為basic_string型別的別名,該型別對應於被用作模板引數的迭代器型別引用的字元(BidirectionalIterator)。也就是說,對於所有使用型別為char(如csub_matchssub_match).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// sub_match::str
#include <iostream>
#include <string>
#include <regex>

int main ()
{
  using namespace std::regex_constants;

  std::cmatch m;

  std::regex_match ( "subject", m, std::regex("(sub)(.*)") );

  std::string output = "matches:\n";
  for (std::cmatch::iterator it = m.begin(); it!=m.end(); ++it) {
    output+= it->str() + "\n";
  }

  std::cout << output << std::endl;
  return 0;
}

輸出
matches:
subject
sub
ject


另見