public member function
<regex>

std::sub_match::operator string_type

operator string_type const()
轉換為字串型別
sub_match 的內容複製到 string 物件中。

它是成員 str 的別名。

引數



返回值

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

string_type是一種成員型別,定義為以下型別的別名:basic_string與用作模板引數的迭代器型別所引用的字元相對應的型別(BidirectionalIterator)。 也就是說,對於所有使用型別字元的物件,stringchar(如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::operator string_type
#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+= std::string(*it) + "\n";
  }

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

輸出
matches:
subject
sub
ject


另見