命名空间
变体
操作

std::towupper

来自 cppreference.cn
< cpp‎ | string‎ | wide
定义于头文件 <cwctype>
std::wint_t towupper( std::wint_t ch );

如果可能,将给定的宽字符转换为大写。

如果 ch 的值既不能表示为 wchar_t 也和宏 WEOF 的值不相等,则行为未定义。

内容

[编辑] 参数

ch - 要转换的宽字符

[编辑] 返回值

ch 的大写版本,如果当前 C 语言环境没有列出大写版本,则返回未修改的 ch

[编辑] 注解

此函数只能执行 1:1 字符映射,例如,'ß' 的大写形式(在某些例外情况下)是双字符字符串 "SS",这无法通过 std::towupper 获得。

ISO 30112 规定了哪些 Unicode 字符对包含在此映射中。

[编辑] 示例

拉丁文 字母 'ſ' (U+017F)'S' (U+0053) 的另一种小写形式。

#include <clocale>
#include <cwctype>
#include <iostream>
 
int main()
{
    wchar_t c = L'\u017f'; // Latin small letter Long S ('ſ')
 
    std::cout << std::hex << std::showbase;
    std::cout << "in the default locale, towupper("
              << static_cast<std::wint_t>(c) << ") = "
              << std::towupper(c) << '\n';
 
    std::setlocale(LC_ALL, "en_US.utf8");
    std::cout << "in Unicode locale, towupper("
              << static_cast<std::wint_t>(c) << ") = "
              << std::towupper(c) << '\n';
}

输出

in the default locale, towupper(0x17f) = 0x17f
in Unicode locale, towupper(0x17f) = 0x53

[编辑] 参见

将宽字符转换为小写
(函数) [编辑]
使用区域设置的 ctype facet 将字符转换为大写
(函数模板) [编辑]
将字符转换为大写
(函数) [编辑]
C 文档 for towupper