public member function
<regex>

std::basic_regex::imbue

locale_type imbue (locale_type loc);
灌輸區域設定
locbasic_regex 物件關聯,並重置正則表示式。

在內部,此函式呼叫內部儲存的 regex traits 物件的 imbue 成員。

此函式會重置 basic_regex 物件,因此它不再匹配任何字元序列(就像使用 regex 的預設建構函式構造的一樣)。 一旦賦予了新值,您可以使用 basic_regex::assignbasic_regex::operator= 將新的正則表示式模式分配給物件。

在構造時,使用預設 regex_traitsbasic_regex 物件使用全域性區域設定 (locale::global)。

引數

loc
要賦予為 basic_regex 的新區域設定的區域設定物件。
locale_type是一個成員型別,定義為其regex traits的同名型別的別名,對於標準 regex_traits 而言,它是標準 locale 型別。

返回值

與呼叫之前與 basic_regex 關聯的區域設定物件
locale_type是一個成員型別,定義為其regex traits的同名型別的別名,對於標準 regex_traits 而言,它是標準 locale 型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// basic_regex::imbue
// note: using regex, a standard alias of basic_regex<char>
#include <iostream>
#include <regex>
#include <locale>

int main ()
{
  std::regex myregex;

  myregex.imbue (std::locale::classic());
  myregex.assign ("sub[a-z]*");
  
  if (std::regex_match ("subject", myregex))
    std::cout << "The string matches." << std::endl;

  return 0;
}

輸出
The string matches.


另見