std:: toupper (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 toupper ( CharT ch, const locale & loc ) ; |
||
若可能,使用给定本地环境的 std::ctype 刻面所指定的转换规则,将字符 ch 转换为大写形式。
目录 |
参数
| ch | - | 字符 |
| loc | - | 区域设置 |
返回值
如果在区域设置中列有对应的大写形式,则返回 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'; // 拉丁文小写字母长S ('ſ') std::cout << std::hex << std::showbase; std::cout << "在默认区域设置中,toupper(" << (std::wint_t)c << ") = " << (std::wint_t)std::toupper(c, std::locale()) << '\n'; std::cout << "在Unicode区域设置中,toupper(" << (std::wint_t)c << ") = " << (std::wint_t)std::toupper(c, std::locale("en_US.utf8")) << '\n'; }
可能的输出:
在默认区域设置中,toupper(0x17f) = 0x17f 在Unicode区域设置中,toupper(0x17f) = 0x53
参见
使用本地环境的
ctype
刻面将字符转换为小写
(函数模板) |
|
|
将字符转换为大写
(函数) |
|
|
将宽字符转换为大写
(函数) |