std::isspace(std::locale)
来自cppreference.com
<tbody>
</tbody>
| 在标头 <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()(OS 限定)。
运行此代码
#include <iostream>
#include <locale>
void try_with(wchar_t c, const char* loc)
{
std::wcout << "isspace('" << c << "', locale(\"" << loc << "\")) 返回 "
<< std::boolalpha << std::isspace(c, std::locale(loc)) << '\n';
}
int main()
{
const wchar_t EM_SPACE = L'\u2003'; // Unicode 字符 'EM SPACE'
try_with(EM_SPACE, "C");
try_with(EM_SPACE, "en_US.UTF8");
}
可能的输出:
isspace(' ', locale("C")) 返回 false
isspace(' ', locale("en_US.UTF8")) 返回 true
参阅
| 检查字符是否为空白间隔字符 (函数) | |
| 检查宽字符是否为空白间隔字符 (函数) |