名稱空間
變體
操作

std::ctype<CharT>::toupper, std::ctype<CharT>::do_toupper

來自 cppreference.com
< cpp‎ | 本地化‎ | ctype
 
 
 
 
 
定義於標頭檔案 <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) 對於字元陣列 [begend) 中的每個字元,如果存在大寫形式,則將其替換為該大寫形式。

目錄

[編輯] 引數

c - 要轉換的字元
beg - 指向要轉換的字元陣列中第一個字元的指標
end - 要轉換的字元陣列的末尾指標(不包含)

[編輯] 返回值

1,3) 大寫字元,如果此區域設定未列出大寫形式,則返回 c
2,4) end

[編輯] 注意

此函式只能執行一對一的字元對映,例如,'ß' 的大寫形式是雙字元字串 "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
(公有成員函式) [編輯]
將字元轉換為大寫
(函式) [編輯]
將寬字元轉換為大寫
(函式) [編輯]