std::tolower(std::locale)
來自 cppreference.com
< cpp | 本地化 (locale)
定義於標頭檔案 <locale> |
||
template< class CharT > CharT tolower( CharT ch, const locale& loc ); |
||
如果可能,使用給定本地化 (locale) 的 std::ctype facet 指定的轉換規則,將字元 ch 轉換為小寫。
目錄 |
[編輯] 引數
ch | - | 字元 |
loc | - | locale |
[編輯] 返回值
如果本地化 (locale) 中列出了 ch 的小寫形式,則返回該小寫形式;否則,返回未更改的 ch。
[編輯] 注意
此函式只能執行 1:1 的字元對映,例如,希臘大寫字母“Σ”有兩種小寫形式,具體取決於單詞中的位置:“σ”和“ς”。在這種情況下,不能使用 std::tolower 來獲取正確的小寫形式。
[編輯] 可能的實現
template<class CharT> CharT tolower(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).tolower(ch); } |
[編輯] 示例
執行此程式碼
#include <cwctype> #include <iostream> #include <locale> int main() { wchar_t c = L'\u0190'; // Latin capital open E ('Ɛ') std::cout << std::hex << std::showbase; std::cout << "in the default locale, tolower(" << (std::wint_t)c << ") = " << (std::wint_t)std::tolower(c, std::locale()) << '\n'; std::cout << "in Unicode locale, tolower(" << (std::wint_t)c << ") = " << (std::wint_t)std::tolower(c, std::locale("en_US.utf8")) << '\n'; }
可能的輸出
in the default locale, tolower(0x190) = 0x190 in Unicode locale, tolower(0x190) = 0x25b
[編輯] 參閱
使用區域設定的 ctype 刻面將字元轉換為大寫 (函式模板) | |
將字元轉換為小寫 (函式) | |
將寬字元轉換為小寫 (函式) |