命名空间
变体
操作

std::ispunct(std::locale)

来自 cppreference.cn
< cpp‎ | locale
 
 
 
 
在头文件 <locale> 中定义
template< class CharT >
bool ispunct( CharT ch, const locale& loc );

检查给定字符是否被给定区域设置的 std::ctype facet 分类为标点符号字符。

目录

[编辑] 参数

ch - 字符
loc - locale

[编辑] 返回值

如果字符被分类为标点符号,则返回 true,否则返回 false

[编辑] 可能的实现

template<class CharT>
bool ispunct(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::punct, ch);
}

[编辑] 示例

演示在不同区域设置(OS 特定)下 std::ispunct() 的用法。

#include <iostream>
#include <locale>
 
int main()
{
    const wchar_t c = L'\u214b'; // upside-down ampersand
 
    std::locale loc1("C");
    std::cout << "ispunct('⅋', C locale) returned "
              << std::boolalpha << std::ispunct(c, loc1) << '\n';
 
    std::locale loc2("en_US.UTF-8");
    std::cout << "ispunct('⅋', Unicode locale) returned "
              << std::boolalpha << std::ispunct(c, loc2) << '\n';
}

可能的输出

isalpha('⅋', C locale) returned false
isalpha('⅋', Unicode locale) returned true

[编辑] 参见

检查字符是否为标点符号字符
(函数) [编辑]
检查宽字符是否为标点符号字符
(函数) [编辑]