public member function
<regex>

std::sub_match::operator string_type

operator string_type const()
Cast to string type
Copies the contents of the sub_match into a string object.

It is an alias of member str.

Parameters

none

Return value

A string with the content referred by the sub_match.

string_type is a member type, defined as an alias of the basic_string type corresponding to the characters being referred by the iterator type used as template argument (BidirectionalIterator). I.e., string for all objects that operate with characters of type char (like csub_match and ssub_match).

Example

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


Output:
matches:
subject
sub
ject

See also