同所有其他来自 <cctype> 的函数,若参数值既不能表示为 unsigned char 又不等于 EOF 则std::isprint 的行为未定义。为了以简单的 char (或 signed char )安全使用此函数,首先要将参数转换为 unsigned char: bool my_isprint(char ch) { return std::isprint(static_cast<unsigned char>(ch)); } 类似地...
begin(), s.end(), // static_cast<int(*)(int)>(std::isprint) // 错误 // [](int c){ return std::isprint(c); } // 错误 // [](char c){ return std::isprint(c); } // 错误 [](unsigned char c){ return std::isprint(c); } // 正确 ); }...
std::isdigit(std::locale) std::ispunct(std::locale) std::isxdigit(std::locale) std::isalnum(std::locale) std::isprint(std::locale) std::isgraph(std::locale) std::toupper(std::locale) std::tolower(std::locale) std::wbuffer_convert std::ctype_base std::codecvt_base std::messages_...
bool my_isprint(char ch) { return std::isprint(static_cast<unsigned char>(ch)); } Similarly, they should not be directly used with standard algorithms when the iterator's value type is char or signed char. Instead, convert the value to unsigned char first: int count_prints(const std:...
intcount_prints(conststd::string&s){returnstd::count_if(s.begin(),s.end(),// static_cast<int(*)(int)>(std::isprint) // wrong// [](int c){ return std::isprint(c); } // wrong// [](char c){ return std::isprint(c); } // wrong[](unsignedcharc){returnstd::isprint(c)...
std::isprint 编辑 定义于头文件 <cctype> int isprint( int ch ); 检查ch 是否为当前安装的 C 本地环境分类为可打印字符。默认的 "C" 本地环境中,下列字符可打印: 数字( 0123456789) 大写字母( ABCDEFGHIJKLMNOPQRSTUVWXYZ) 小写字母( abcdefghijklmnopqrstuvwxyz) 标点字符( !"#$%&'()*+,-./...
std::isprint(std::locale) 定义于头文件<locale> template<classcharT> boolisprint(charT ch,constlocale&loc); 检查给定字符是否为给定 locale 的std::ctype平面分类为可打印字符(包含空格)。 参数 ch-字符 loc-本地环境 返回值 若字符被分类为可打印则返回true,否则返回false。
std::isprint(std::locale)C++ 本地化库 定义于头文件 <locale> template< class charT > bool isprint( charT ch, const locale& loc ); 检查给定字符是否为给定 locale 的 std::ctype 平面分类为可打印字符(包含空格)。 参数ch - 字符 loc - 本地环境 返回值...
intcount_prints(conststd::string&s){returnstd::count_if(s.begin(), s.end(),// static_cast<int(*)(int)>(std::isprint) // wrong// [](int c){ return std::isprint(c); } // wrong// [](char c){ return std::isprint(c); } // wrong[](unsignedcharc){returnstd::isprint(c...
std::isprint(std::locale) From cppreference.com <cpp |locale Localization library Character classification and conversion Character classification isspace isblank (C++11) iscntrl isupper islower isalpha ispunct isdigit isxdigit isalnum isprint