c语言ctype中替换查找字符,c – std :: ctype是否总是按“C”语言环境对字符进行分类?...

该标准需要默认构造的std :: ctype< char>通过§22.4.1.3.3匹配最小“C”语言环境[facet.ctype.char.statics] / 1

static const mask* classic_table() noexcept;

Returns: A pointer to the initial element of an array of size table_size which represents the classifications of characters in the “C” locale

分类成员函数is()是根据table()定义的,table()是根据classic_table()定义的,除非为ctype< char>的构造函数提供了另一个表

我更新了cppreference以更恰当地匹配这些要求(对于std :: ctype< wchar_t>也说“C”)

要回答第二个问题,使用std :: locale loc(std :: locale(“en_US.UTF8”),new std :: ctype< char>)构建语言环境;将使用您指定的ctype facet(因此,“C”)来对窄字符进行分类,但它是多余的:普通std :: locale(“en_US.UTF8”)的窄字符分类(至少在GNU实现中)是完全相同的:

#include

#include

#include

int main()

{

std::locale loc1("en_US.UTF8");

const std::ctype_base::mask* tbl1 =

std::use_facet<:ctype>>(loc1).table();

std::locale loc2(std::locale("en_US.UTF8"),new std::ctype);

const std::ctype_base::mask* tbl2 =

std::use_facet<:ctype>>(loc2).table();

for(size_t n = 0; n < 256; ++n)

assert(tbl1[n] == tbl2[n]);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值