std::ctype<div class="t-tr-text"><Char>来<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">原文:</div><div class="t-tr-dropdown-orig"><char></div><div class="t-tr-dropdown-notes">这段文字是通过 [http://translate.google.com Google Translate] 自动翻译生成的。<br/>您可以帮助我们检查、纠正翻译中的错误。详情请点击[http://en.cppreference.com/w/Cppreference:MachineTranslations 这里]。</div></div></div></div></div>
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <locale> 中定义
|
||
template<> class ctype<char>; |
||
这种专业化的std::ctype封装类型char的字符分类功能。与通用std::ctype,表查找,分类字符。的的基类std::ctype<char>实现字符分类等同于“C”语言环境。的分类规则,可以扩展或修改,如果作为std::ctype_byname<char>或作为一个用户定义的衍生的小面构成。所有std::istream格式的输入功能,在输入过程中解析std::ctype<char>需要使用的字符分级.
原文:
This specialization of std::ctype encapsulates character classification features for type char. Unlike general-purpose std::ctype, table lookup is used to classify characters. The base class std::ctype<char> implements character classification equivalent to the "C" locale. The classification rules can be extended or modified if constructed as std::ctype_byname<char> or as a user-defined derived facet. All std::istream formatted input functions are required to use std::ctype<char> for character classing during input parsing.
目录 |
[编辑] 会员类型
会员类型
|
Definition |
char_type
|
char
|
[编辑] 成员函数
构造一个新的std::ctype<char>方面 原文: constructs a new std::ctype<char> facet (公共成员函数) | |
解构一个std::ctype<char>方面 (受保护的成员函数) | |
得到的字符分类表 原文: obtains the character classification table (公共成员函数) | |
[静态的]</div></div>
|
获得“C”区域设置字符分类表 原文: obtains the "C" locale character classification table (公共静态成员函数) |
分类的字符或字符序列时,使用的分类表 原文: classifies a character or a character sequence, using the classification table (公共成员函数) | |
找到的第一个字符序列中符合给定的分类,使用的分类表 原文: locates the first character in a sequence that conforms to given classification, using the classification table (公共成员函数) | |
locates the first character in a sequence that fails given classification, using the classification table (公共成员函数) | |
调用 do_toupper (公共成员函数of std::ctype )
| |
调用 do_tolower (公共成员函数of std::ctype )
| |
调用 do_widen (公共成员函数of std::ctype )
| |
调用 do_narrow (公共成员函数of std::ctype )
|
[编辑] 受保护的成员函数
[虚]</div></div>
|
将一个或多个字符转换为大写 原文: converts a character or characters to uppercase (虚拟保护成员函数of std::ctype )
|
[虚]</div></div>
|
一个或多个字符转换为小写 原文: converts a character or characters to lowercase (虚拟保护成员函数of std::ctype )
|
[虚]</div></div>
|
将一个或多个字符从 char charT 原文: converts a character or characters from char to charT (虚拟保护成员函数of std::ctype )
|
[虚]</div></div>
|
将一个或多个字符从 charT char 原文: converts a character or characters from charT to char (虚拟保护成员函数of std::ctype )
|
[编辑] 会员对象
static std::locale::id id [静态的]</div></div>
|
“ID”的语言环境 (公共静态成员常量) |
static const std::size_t table_size [静态的]</div></div>
|
的分类表的大小,256个在leaest的 原文: size of the classification table, at leaest 256 (公共静态成员常量) |
Inherited from std::ctype_base
Member types
类型
|
Definition |
mask
|
未指定的位掩码类型(枚举,整数类型,或bitset的)
原文: unspecified bitmask type (enumeration, integer type, or bitset) |
Member constants
space [静态的]</div></div>
|
mask 识别的空白字符分类 原文: the value of mask identifying whitespace character classification (公共静态成员常量) |
print [静态的]</div></div>
|
mask 确定可打印字符分类的价值 原文: the value of mask identifying printable character classification (公共静态成员常量) |
cntrl [静态的]</div></div>
|
mask 识别控制字符分类 原文: the value of mask identifying control character classification (公共静态成员常量) |
upper [静态的]</div></div>
|
mask 确定的价值大写字符分类 原文: the value of mask identifying uppercase character classification (公共静态成员常量) |
lower [静态的]</div></div>
|
值 mask 识别小写字母分类 原文: the value of mask identifying lowercase character classification (公共静态成员常量) |
alpha [静态的]</div></div>
|
mask 识别英文字母分类的价值 原文: the value of mask identifying alphabetic character classification (公共静态成员常量) |
digit [静态的]</div></div>
|
mask 识别数字字符分类的价值 原文: the value of mask identifying digit character classification (公共静态成员常量) |
punct [静态的]</div></div>
|
mask 识别的标点字符分类 原文: the value of mask identifying punctuation character classification (公共静态成员常量) |
xdigit [静态的]</div></div>
|
mask 识别十六进制数字字符分类的价值 原文: the value of mask identifying hexadecimal digit character classification (公共静态成员常量) |
blank [静态的] (C++11)</div></div>
|
mask 识别空白字符分类的价值 原文: the value of mask identifying blank character classification (公共静态成员常量) |
alnum [静态的]</div></div>
|
alpha | digit (公共静态成员常量) |
graph [静态的]</div></div>
|
alnum | punct (公共静态成员常量) |
</div>
[编辑] 示例
下面的示例演示的CTYPE <Char>来修改来标记一个CSV文件
原文:
The following example demonstrates modification of ctype<char> to tokenize of a CSV file
#include <iostream> #include <vector> #include <locale> #include <sstream> // This ctype facet classifies commas and endlines as whitespace struct csv_whitespace : std::ctype<char> { static const mask* make_table() { // make a copy of the "C" locale table static std::vector<mask> v(classic_table(), classic_table() + table_size); v[','] |= space; // comma will be classified as whitespace v[' '] &= ~space; // space will not be classified as whitespace return &v[0]; } csv_whitespace(std::size_t refs = 0) : ctype(make_table(), false, refs) {} }; int main() { std::string in = "Column 1,Column 2,Column 3\n123,456,789"; std::string token; std::cout << "default locale:\n"; std::istringstream s1(in); while(s1 >> token) std::cout << " " << token << '\n'; std::cout << "locale with modified ctype:\n"; std::istringstream s2(in); s2.imbue(std::locale(s2.getloc(), new csv_whitespace())); while(s2 >> token) std::cout << " " << token<< '\n'; }
输出:
default locale: Column 1,Column 2,Column 3 123,456,789 locale with modified ctype: Column 1 Column 2 Column 3 123 456 789
[编辑] 另请参阅
定义字符分类表 原文: defines character classification tables (类模板) | |
定义字符分类 原文: defines character classification categories (类模板) | |
创建一个CTYPE方面命名的语言环境 原文: creates a ctype facet for the named locale (类模板) |