首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ctype<char>

Defined in header <locale>

template<> class ctype<char>;

这种专业化std::ctype封装类型的字符分类特性char.不像一般用途std::ctype,它使用虚拟函数,这种专门化使用表查找来对字符%28进行分类,这通常要快于%29。

基类std::ctype<char>实现与最小“C”区域设置等效的字符分类。如果使用非默认的分类表参数构造,则可以扩展或修改分类规则,如果构造为std::ctype_byname<char>或者作为用户定义的派生面。全std::istream需要使用格式化的输入函数。std::ctype<char>用于输入解析期间的字符分类。

二次

二次

继承图

成员类型

Member type

Definition

char_type

char

成员函数

(constructor)

constructs a new std::ctype<char> facet (public member function)

(destructor)

destructs a std::ctype<char> facet (protected member function)

table

obtains the character classification table (public member function)

classic_table static

obtains the "C" locale character classification table (public static member function)

is

classifies a character or a character sequence, using the classification table (public member function)

scan_is

locates the first character in a sequence that conforms to given classification, using the classification table (public member function)

scan_not

locates the first character in a sequence that fails given classification, using the classification table (public member function)

toupper

invokes do_toupper (public member function of std::ctype)

tolower

invokes do_tolower (public member function of std::ctype)

widen

invokes do_widen (public member function of std::ctype)

narrow

invokes do_narrow (public member function of std::ctype)

受保护成员函数

do_toupper virtual

converts a character or characters to uppercase (virtual protected member function of std::ctype)

do_tolower virtual

converts a character or characters to lowercase (virtual protected member function of std::ctype)

do_widen virtual

converts a character or characters from char to charT (virtual protected member function of std::ctype)

do_narrow virtual

converts a character or characters from charT to char (virtual protected member function of std::ctype)

成员对象

static std::locale::id id static

id of the locale (public static member constant)

static const std::size_t table_size static

size of the classification table, at least 256 (public static member constant)

从STD::Ctype继承而来[医]底座

成员类型

Type

Definition

mask

unspecified bitmask type (enumeration, integer type, or bitset)

成员常数

space static

the value of mask identifying whitespace character classification (public static member constant)

print static

the value of mask identifying printable character classification (public static member constant)

cntrl static

the value of mask identifying control character classification (public static member constant)

upper static

the value of mask identifying uppercase character classification (public static member constant)

lower static

the value of mask identifying lowercase character classification (public static member constant)

alpha static

the value of mask identifying alphabetic character classification (public static member constant)

digit static

the value of mask identifying digit character classification (public static member constant)

punct static

the value of mask identifying punctuation character classification (public static member constant)

xdigit static

the value of mask identifying hexadecimal digit character classification (public static member constant)

blank static

the value of mask identifying blank character classification (public static member constant)

alnum static

alpha | digit (public static member constant)

graph static

alnum | punct (public static member constant)

下面的示例演示修改Ctype<char>若要标记逗号分隔的值,请执行以下操作。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
default locale:
  Column
  1,Column
  2,Column
  3
  123,456,789
locale with modified ctype:
  Column 1
  Column 2
  Column 3
  123
  456
  789

二次

另见

ctype

defines character classification tables (class template)

ctype_base

defines character classification categories (class template)

ctype_byname

creates a ctype facet for the named locale (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券