std::isspace(std::locale)
來自 cppreference.com
< cpp | 本地化(locale)
定義於標頭檔案 <locale> |
||
template< class CharT > bool isspace( CharT ch, const locale& loc ); |
||
檢查給定字元是否被給定本地環境的 std::ctype facet 分類為空白字元。
目錄 |
[編輯] 引數
ch | - | 字元 |
loc | - | locale |
[編輯] 返回值
如果字元被分類為空白字元,則返回 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
[編輯] 參閱
檢查字元是否為空格字元 (函式) | |
檢查寬字元是否為空格字元 (函式) |