命名空间
变体
操作

std::tolower(std::locale)

来自 cppreference.cn
< cpp‎ | locale
 
 
 
 
定义于头文件 <locale>
template< class CharT >
CharT tolower( CharT ch, const locale& loc );

如果可能,使用给定区域设置的 std::ctype facet 指定的转换规则,将字符 ch 转换为小写。

目录

[编辑] 参数

ch - 字符
loc - 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 facet 将字符转换为大写
(函数模板) [编辑]
将字符转换为小写
(函数) [编辑]
将宽字符转换为小写
(函数) [编辑]