std::ctype<CharT>::toupper, std::ctype<CharT>::do_toupper
来自 cppreference.com
在头文件 <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) 公共成员函数,调用最派生类的受保护虚拟成员函数
do_toupper
。3) 如果此语言环境定义了大写形式,则将字符 c 转换为大写。
4) 对于字符数组
[
beg,
end)
中的每个字符,如果存在大写形式,则将字符替换为该大写形式。内容 |
[编辑] 参数
c | - | 要转换的字符 |
beg | - | 指向要转换的字符数组中第一个字符的指针 |
end | - | 指向要转换的字符数组的末尾指针 |
[编辑] 返回值
1,3) 大写字符,如果此语言环境中没有列出大写形式,则为 c。
2,4) end
[编辑] 说明
此函数只能执行 1:1 字符映射,例如 'ß' 的大写形式是两个字符的字符串 "SS"(有一些例外 - 参见 «Capital ẞ»),这无法通过 do_toupper
获得。
[编辑] 示例
运行这段代码
#include <iostream> #include <locale> 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'δ'); 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"; }
输出
In US English UTF-8 locale: Upper case form of 's' is S Upper case form of 'ſ' is S Upper case form of 'δ' is Δ Upper case form of 'ö' is Ö 'ß' has no upper case form Uppercase form of the string 'Hello, World!' is 'HELLO, WORLD!'
[编辑] 参见
调用 do_tolower (公共成员函数) | |
将字符转换为大写 (函数) | |
将宽字符转换为大写 (函数) |