std::iscntrl
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cctype> で定義
|
||
int iscntrl( int ch ); |
||
現在設定されている C のロケールによる分類において、指定された文字が制御文字かどうか調べます。 デフォルトの "C" ロケールでは、制御文字はコード 0x00-0x1F および 0x7F の文字です。
ch の値が unsigned char で表現できず、 EOF とも等しくない場合、動作は未定義です。
引数
| ch | - | 分類する文字 |
戻り値
文字が制御文字であれば非ゼロの値、そうでなければゼロ。
ノート
<cctype> の他のすべての関数と同様に、引数の値が unsigned char で表現できず、 EOF とも等しくない場合、 std::iscntrl の動作は未定義です。 プレーンな char (または signed char) でこれらの関数を安全に使用するためには、まず引数を unsigned char に変換するべきです。
bool my_iscntrl(char ch)
{
return std::iscntrl(static_cast<unsigned char>(ch));
}
同様に、イテレータの値型が char または signed char のとき、標準のアルゴリズムで直接これらを使用するべきではありません。 代わりに、まず値を unsigned char に変換してください。
int count_cntrls(const std::string& s)
{
return std::count_if(s.begin(), s.end(),
// static_cast<int(*)(int)>(std::iscntrl) // wrong
// [](int c){ return std::iscntrl(c); } // wrong
// [](char c){ return std::iscntrl(c); } // wrong
[](unsigned char c){ return std::iscntrl(c); } // correct
);
}
例
Run this code
#include <iostream>
#include <cctype>
#include <clocale>
int main()
{
unsigned char c = '\x94'; // the control code CCH in ISO-8859-1
std::cout << "iscntrl(\'\\x94\', default C locale) returned "
<< std::boolalpha <<