当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


C++ towupper()用法及代码示例

C++ 中的towupper() 函数将给定的宽字符转换为大写。

towupper() 函数在<cwctype> 头文件中定义。

towupper()原型

wint_t towupper( wint_t ch );

towupper() 函数将 ch 转换为其大写版本(如果存在)。如果宽字符的大写版本不存在,则保持不变。

从 a 到 z 的小写字母分别转换为从 A 到 Z 的大写字母。

参数:

  • ch : 要转换的宽字符

返回:

  • towupper() 函数返回 ch 的大写版本(如果存在)。否则返回 ch。

示例:towupper() 函数如何工作?

#include <cwctype>
#include <cwchar>
#include <iostream>
#include <clocale>
using namespace std;

int main()
{
    setlocale(LC_ALL, "en_US.UTF-8");
    
    wchar_t str[] = L"Ĵōhn Deńvėr";
    wcout << L"The uppercase version of \"" << str << L"\" is ";
    
    for (int i=0; i<wcslen(str); i++)
        putwchar(towupper(str[i]));
    
    return 0;
}

运行程序时,输出将是:

The uppercase version of "Ĵōhn Deńvėr" is ĴŌHN DEŃVĖR

相关用法


注:本文由纯净天空筛选整理自 C++ towupper()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。