std:: isspace (std::locale)
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Localization library
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<locale>
|
||
|
template
<
class
CharT
>
bool isspace ( CharT ch, const locale & loc ) ; |
||
检查给定字符是否被指定区域的 std::ctype 刻面归类为空白字符。
目录 |
参数
| ch | - | 字符 |
| loc | - | 区域设置 |
返回值
如果字符被分类为空白字符,则返回 true ,否则返回 false 。
可能的实现
template<class CharT> bool isspace(CharT ch, const std::locale& loc) { return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::space, ch); } |
示例
演示了
std::isspace()
在不同区域设置(操作系统特定)中的使用。
运行此代码
#include <iostream> #include <locale> void try_with(wchar_t c, const char* loc) { std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) returned " << std::boolalpha << std::isspace(c, std::locale(loc)) << '\n'; } int main() { const wchar_t EM_SPACE = L'\u2003'; // Unicode character 'EM SPACE' try_with(EM_SPACE, "C"); try_with(EM_SPACE, "en_US.UTF8"); }
可能的输出:
isspace(' ', locale("C")) returned false
isspace(' ', locale("en_US.UTF8")) returned true
参见
|
检查字符是否为空白字符
(function) |
|
|
检查宽字符是否为空白字符
(function) |