std::toupper(std::locale)_C++中文网
| template< class charT > |
||
用给定 loacale 的 std::ctype 平面所指定的转换规则,若可能则转换字符 ch 为大写。
参数
返回值
若 ch 的大写形式列于 locale 则返回它,否则返回不更改的 ch 。
注意
此函数只能进行 1:1 字符映射,例如 'ß' 的大写形式(有一些例外)是双字符字符串 "SS" ,它无法以 do_toupper 获得。
可能的实现
示例
#include <iostream> #include <cwctype> #include <locale> int main() { wchar_t c = L'\u017f'; // 拉丁文小写字母长 S ('ſ') std::cout << std::hex << std::showbase; std::cout << "in the default locale, toupper(" << (std::wint_t)c << ") = " << std::toupper(c, std::locale()) << '\n'; std::cout << "in Unicode locale, toupper(" << (std::wint_t)c << ") = " << std::toupper(c, std::locale("en_US.utf8")) << '\n'; }
输出:
in the default locale, toupper(0x17f) = 0x17f in Unicode locale, toupper(0x17f) = 0x53