公共成員函式
<regex>

std::match_results::ready

bool ready() const;
測試結果是否就緒
返回值true如果 match_results 物件具有完全建立的結果狀態,並且false否則為 false。

當物件是 預設構造的,此值初始化為false。 任何呼叫 regex_matchregex_search 並將 match_results 物件作為引數都會將此值設定為true,即使該函式未能成功找到任何匹配項。

要檢查在特定呼叫 regex_matchregex_search 之後是否存在匹配項,您可以使用 match_results::empty

當物件透過解引用有效的 regex_iterator 獲得時,此值始終為true.

引數



返回值

true如果物件具有完全建立的結果狀態。false否則為 false。

示例

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

int main ()
{
  std::string mystring ("subject");
  std::smatch mymatch;
  std::regex myregex ("sub.*");

  std::cout << std::boolalpha;
  std::cout << "mymatch.ready() is " << mymatch.ready() << std::endl;

  std::regex_match ( mystring, mymatch, myregex );
  std::cout << "attempting match..." << std::endl;
  
  std::cout << "mymatch.ready() is " << mymatch.ready() << std::endl;

  if (mymatch.ready()) std::cout << "matched: " << mymatch[0] << std::endl;

  return 0;
}

輸出
mymatch.ready() is false
attempting match...
mymatch.ready() is true
matched: subject


另見