C++ 本地化庫 - widen



描述

它用於擴充套件字元,在內部,此函式簡單地呼叫虛擬受保護成員 do_widen,在泛型模板和 char 特化(ctype<char>)中,預設情況下,它都執行上述操作。

宣告

以下是 std::ctype::widen 的宣告。

C++98

	
char_type tolower (char_type c) const;

C++11

char_type tolower (char_type c) const;

引數

  • c − 它是一個 char 型別。

  • low,high − 它是指向字元序列的開頭和結尾的指標。

  • to − 它是指向方面字元型別元素範圍的指標。

返回值

它返回 c 的轉換結果。

異常

如果丟擲異常,方面物件不會發生任何更改,儘管範圍內的字元可能已受到影響。

資料競爭

http://tpcg.io/YqaGeY

訪問物件和範圍 [low,high) 中的元素。

示例

下面的示例解釋了 std::ctype::widen。

#include <iostream>
#include <locale>
int main () {
   std::locale loc;

   const char narrow_phrase[] = "Sairamkrishna Mammahe";
   wchar_t wide_phrase[sizeof(narrow_phrase)];

   std::wcout << L"The first wide character is: ";
   wchar_t wc = std::use_facet< std::ctype<wchar_t> >(loc).widen ( *narrow_phrase );
   std::wcout << wc << std::endl;

   std::wcout << L"The wide-character phrase is: ";
   std::use_facet< std::ctype<wchar_t> >(loc).widen (narrow_phrase,
                                                    narrow_phrase+sizeof(narrow_phrase),
                                                    wide_phrase);
   std::wcout << wide_phrase << std::endl;

   return 0;
}

讓我們編譯並執行上面的程式,這將產生以下結果:

The first wide character is: S
The wide-character phrase is: Sairamkrishna Mammahe
locale.htm
廣告