名稱空間
變體
操作

std::ispunct(std::locale)

來自 cppreference.com
< cpp‎ | locale
 
 
 
 
定義於標頭檔案 <locale>
template< class CharT >
bool ispunct( CharT ch, const locale& loc );

檢查給定字元是否被給定 locale 的 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-specific)下使用 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

[編輯] 參閱

檢查字元是否為標點符號
(函式) [編輯]
檢查寬字元是否為標點符號
(函式) [編輯]