名前空間
変種
操作

std::toupper

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

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

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

目次

[編集]引数

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

[編集]戻り値

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

[編集]ノート

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

char my_toupper(char ch){returnstatic_cast<char>(std::toupper(static_cast<unsignedchar>(ch)));}

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

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[](unsignedchar c){return std::toupper(c);}// correct);return s;}

[編集]

#include <iostream>#include <cctype>#include <clocale>   int main(){unsignedchar 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]
close