名前空間
変種
操作

std::toupper

提供: cppreference.com
< cpp‎ | string‎ | byte
ヘッダ <cctype> で定義
int toupper( int ch );

現在設定されている C のロケールよって定義されている文字変換ルールに従って、指定された文字を大文字に変換します。

デフォルトの "C" ロケールでは、小文字 abcdefghijklmnopqrstuvwxyz が対応する大文字 ABCDEFGHIJKLMNOPQRSTUVWXYZ に変換されます。

目次

[編集] 引数

ch - 変換する文字。 ch の値が unsigned char で表現できず、 EOF とも等しくない場合、動作は未定義です。

[編集] 戻り値

変換した文字、または現在の C のロケールに大文字のバージョンがない場合は無変更の ch

[編集] ノート

<cctype> の他のすべての関数と同様に、引数の値が unsigned char で表現できず、 EOF とも等しくない場合、 std::toupper の動作は未定義です。 プレーンな char (または signed char) でこれらの関数を安全に使用するためには、まず引数を unsigned char に変換するべきです。

char my_toupper(char ch)
{
    return static_cast<char>(std::toupper(static_cast<unsigned char>(ch)));
}

同様に、イテレータの値型が char または signed char のとき、標準のアルゴリズムで直接これらを使用するべきではありません。 代わりに、まず値��� unsigned char に変換してください。

std::string str_toupper(std::string s) {
    std::transform(s.begin(), s.end(), s.begin(), 
                // static_cast<int(*)(int)>(std::toupper)         // wrong
                // [](int c){ return std::toupper(c); }           // wrong
                // [](char c){ return std::toupper(c); }          // wrong
                   [](unsigned char c){ return std::toupper(c); } // correct
                  );
    return s;
}

[編集]

#include <iostream>
#include <cctype>
#include <clocale>
 
int main()
{
    unsigned char c = '\xb8'; // the character ž in ISO-8859-15
                              // but ¸ (cedilla) in ISO-8859-1 
 
    std::setlocale(LC_ALL, "en_US.iso88591");
    std::cout << std::hex << std::showbase;
    std::cout << "in iso8859-1, toupper('0xb8') gives " << std::toupper(c) << '\n';
    std::setlocale(LC_ALL, "en_US.iso885915");
    std::cout << "in iso8859-15, toupper('0xb8') gives " << std::toupper(c) << '\n';
}

出力:

in iso8859-1, toupper('0xb8') gives 0xb8
in iso8859-15, toupper('0xb8') gives 0xb4


[編集] 関連項目

文字を小文字に変換します
(関数) [edit]
指定されたロケールの ctype ファセットを使用して文字を大文字に変換します
(関数テンプレート) [edit]
ワイド文字を大文字に変換します
(関数) [edit]