std:: tolower (std::locale)
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Localization library
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<locale>
|
||
|
template
<
class
CharT
>
CharT tolower ( CharT ch, const locale & loc ) ; |
||
若可能,使用给定本地环境的 std::ctype 刻面所指定的转换规则,将字符 ch 转换为小写形式。
目录 |
参数
| ch | - | 字符 |
| loc | - | 区域设置 |
返回值
返回 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'; // 拉丁文大写开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 刻面将字符转换为大写
(函数模板) |
|
|
将字符转换为小写
(函数) |
|
|
将宽字符转换为小写
(函数) |