public member function
<regex>

std::match_results::suffix

const_reference suffix() const;
返回字尾
返回對 sub_match 物件的引用,該物件表示目標序列中匹配序列結束後出現的字元序列。

match_results 物件應該是 ready 狀態,這在使用 regex_matchregex_search 呼叫中作為適當的引數傳遞之後發生。

引數



返回值

對描述字尾的 sub_match 物件的引用。

成員型別const_reference是對應 const sub_match 型別的引用的別名。

示例

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

int main ()
{
  std::string s ("there is a needle in this haystack");
  std::smatch m;
  std::regex e ("needle");

  std::cout << "searching for needle in [" << s << "]\n";
  std::regex_search ( s, m, e );

  if (m.ready()) {
    std::cout << m[0] << " found!\n";
    std::cout << "prefix: [" << m.prefix() << "]\n";
    std::cout << "suffix: [" << m.suffix() << "]\n";
  }

  return 0;
}

輸出
searching for needle in [there is a needle in this haystack]
needle found!
prefix: [there is a ]
suffix: [ in this haystack]



另見