首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ctype::toupper

Defined in header <locale>

?

?

public: CharT toupper( CharT c ) const;

(1)

?

public: const CharT* toupper( CharT* beg, const CharT* end ) const;

(2)

?

protected: virtual CharT do_toupper( CharT c ) const;

(3)

?

protected: virtual const CharT* do_toupper( CharT* beg, const CharT* end ) const;

(4)

?

1,2%29的公共成员函数,调用受保护的虚拟成员函数。do_toupper最派生的类。

3%29转换字符c如果大写窗体由此区域设置定义,则为大写。

4%29对字符数组中的每个字符[beg, end),如果存在大写形式,则将字符替换为该大写形式。

参数

c

-

character to convert

beg

-

pointer to the first character in an array of characters to convert

end

-

one past the end pointer for the array of characters to convert

返回值

1,3%29大写字符或c如果此区域设置没有列出大写形式。

2,4%29end...

注记

这个函数只能执行01:1的字符映射,例如,大写形式%27%27是%28,但有一些例外,即双字符字符串“ss”,它不能由do_toupper...

二次

代码语言:javascript
复制
#include <locale>
#include <iostream>
 
void try_upper(const std::ctype<wchar_t>& f, wchar_t c)
{
    wchar_t up = f.toupper(c);
    if (up != c) {
        std::wcout << "Upper case form of \'" << c << "' is " << up << '\n';
    } else {
        std::wcout << '\'' << c << "' has no upper case form\n";
    }
}
 
int main()
{
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << "In US English UTF-8 locale:\n";
    auto& f = std::use_facet<std::ctype<wchar_t>>(std::locale());
    try_upper(f, L's');
    try_upper(f, L'?');
    try_upper(f, L'?');
 
    std::wstring str = L"Hello, World!";
    std::wcout << "Uppercase form of the string '" << str << "' is ";
    f.toupper(&str[0], &str[0] + str.size());
    std::wcout << "'" << str << "'\n";
}

二次

产出:

二次

代码语言:javascript
复制
In US English UTF-8 locale:
Upper case form of 's' is S
Upper case form of '?' is S
'?' has no upper case form
Uppercase form of the string 'Hello, World!' is 'HELLO, WORLD!'

二次

另见

tolower

invokes do_tolower (public member function)

toupper

converts a character to uppercase (function)

towupper

converts a wide character to uppercase (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com