Namespaces
Variants

std:: isupper

From cppreference.net
ヘッダーで定義 <cctype>
int isupper ( int ch ) ;

指定された文字が、現在インストールされているCロケールで分類される大文字であるかどうかをチェックします。デフォルトの "C" ロケールでは、 std::isupper は大文字( ABCDEFGHIJKLMNOPQRSTUVWXYZ )に対してのみ非ゼロの値を返します。

std::isupper が非ゼロの値を返す場合、同じCロケールにおいて同じ文字に対して std::iscntrl std::isdigit std::ispunct 、および std::isspace がゼロを返すことが保証されます。

ch の値が unsigned char として表現不可能であり、かつ EOF と等しくない場合、動作は未定義です。

目次

パラメータ

ch - 分類対象の文字

戻り値

文字が大文字の場合、非ゼロの値。それ以外の場合、ゼロ。

注記

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

bool my_isupper(char ch)
{
    return std::isupper(static_cast<unsigned char>(ch));
}

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

int count_uppers(const std::string& s)
{
    return std::count_if(s.begin(), s.end(),
                      // static_cast<int(*)(int)>(std::isupper)         // 誤り
                      // [](int c){ return std::isupper(c); }           // 誤り
                      // [](char c){ return std::isupper(c); }          // 誤り
                         [](unsigned char c){ return std::isupper(c); } // 正しい
                        );
}

#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
    unsigned char c = '\xc6'; // ISO-8859-1における文字 Æ
    std::cout << "isupper(\'\\xc6\', default C locale) returned "
              << std::boolalpha << (bool)std::isupper(c) << '\n';
    std::setlocale(LC_ALL, "en_GB.iso88591");
    std::cout << "isupper(\'\\xc6\', ISO-8859-1 locale) returned "
              << std::boolalpha << (bool)std::isupper(c) << '\n';
}

出力例:

isupper('\xc6', default C locale) returned false
isupper('\xc6', ISO-8859-1 locale) returned true

関連項目

ロケールによって大文字として分類されるかどうかをチェックする
(関数テンプレート)
ワイド文字が大文字かどうかをチェックする
(関数)
**注記**: このHTMLフラグメントには翻訳すべきテキストがほとんど含まれていません。数値範囲「71–90」と記号「–」は元のまま保持されています。` `タグ内のすべての内容(エスケープシーケンス、文字列、数値)はC++関連のコードとして保持されています。
ASCII値 文字

iscntrl
iswcntrl

isprint
iswprint

isspace
iswspace

isblank
iswblank

isgraph
iswgraph

ispunct
iswpunct

isalnum
iswalnum

isalpha
iswalpha

isupper
iswupper

islower
iswlower

isdigit
iswdigit

isxdigit
iswxdigit

10進数 16進数 8進数
0–8 \x0 \x8 \0 \10 制御コード ( NUL など) ≠0 0 0 0 0 0 0 0 0 0 0 0
9 \x9 \11 タブ文字 ( \t ) ≠0 0 ≠0 ≠0 0 0 0 0 0 0 0 0
10–13 \xA \xD \12 \15 空白文字 ( \n , \v , \f , \r ) ≠0 0 ≠0 0 0 0 0 0 0 0 0 0
14–31 \xE \x1F \16 \37 制御コード ≠0 0 0 0 0 0 0 0 0 0 0 0
32 \x20 \40 スペース 0 ≠0 ≠0 ≠0 0 0 0 0 0 0 0 0
33–47 \x21 \x2F \41 \57 !"#$%&'()*+,-./ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
48–57 \x30 \x39 \60 \71 0123456789 0 ≠0 0 0 ≠0 0 ≠0 0 0 0 ≠0 ≠0
58–64 \x3A \x40 \72 \100 :;<=>?@ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
65–70 \x41 \x46 \101 \106 ABCDEF 0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 ≠0
71–90 \x47 \x5A \107 \132 GHIJKLMNOP
QRSTUVWXYZ
0 ≠0 0 0 ≠0 0 ≠0 ≠0 ≠0 0 0 0
91–96 \x5B \x60 \133 \140 [\]^_` 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
97–102 \x61 \x66 \141 \146 abcdef 0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 ≠0
103–122 \x67 \x7A \147 \172 ghijklmnop
qrstuvwxyz
0 ≠0 0 0 ≠0 0 ≠0 ≠0 0 ≠0 0 0
123–126 \x7B \x7E \172 \176 {|}~ 0 ≠0 0 0 ≠0 ≠0 0 0 0 0 0 0
127 \x7F \177 バックスペース文字 ( DEL ) ≠0 0 0 0 0 0 0 0 0 0 0 0