std::toupper(std::locale)
來自 cppreference.com
定義於標頭檔案 <locale> |
||
template< class CharT > CharT toupper( CharT ch, const locale& loc ); |
||
使用給定 locale 的 std::ctype facet 指定的轉換規則,將字元 ch 轉換為大寫(如果可能)。
目錄 |
[編輯] 引數
ch | - | 字元 |
loc | - | locale |
[編輯] 返回值
如果 locale 中列出了 ch 的大寫形式,則返回其大寫形式;否則返回 ch 不變。
[編輯] 注意
此函式只能執行 1:1 字元對映,例如,'ß' 的大寫形式(除少數例外)是兩個字元的字串 "SS",這不能透過 std::toupper 獲得。
[編輯] 可能的實現
template<class CharT> CharT toupper(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).toupper(ch); } |
[編輯] 示例
執行此程式碼
#include <cwctype> #include <iostream> #include <locale> int main() { wchar_t c = L'\u017f'; // Latin small letter Long S ('ſ') std::cout << std::hex << std::showbase; std::cout << "in the default locale, toupper(" << (std::wint_t)c << ") = " << (std::wint_t)std::toupper(c, std::locale()) << '\n'; std::cout << "in Unicode locale, toupper(" << (std::wint_t)c << ") = " << (std::wint_t)std::toupper(c, std::locale("en_US.utf8")) << '\n'; }
可能的輸出
in the default locale, toupper(0x17f) = 0x17f in Unicode locale, toupper(0x17f) = 0x53
[編輯] 另請參閱
使用區域設定的 ctype 刻面將字元轉換為小寫(函式模板) | |
將字元轉換為大寫 (函式) | |
將寬字元轉換為大寫 (函式) |