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

std::isdigit(std::locale)

Defined in header <locale>

?

?

template< class charT > bool isdigit( charT ch, const locale& loc );

?

?

检查给定字符是否被给定的区域设置%27s分类为数字std::ctype小面。

参数

ch

-

character

loc

-

locale

返回值

回报true如果字符被归类为数字,false否则。

可能的实施

模板<类图表>bool是数字%28图表ch,Const std::locale&loc%29{返回std::use[医]facet<std::Ctype<charT>>%28 loc%29 is%28 std::Ctype[医]基数::位,ch%29;}

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <locale>
#include <string>
#include <set>
 
struct jdigit_ctype : std::ctype<wchar_t>
{
    std::set<wchar_t> jdigits{L'一',L'二',L'三',L'四',L'五',L'六',L'七',L'八',L'九',L'十'};
    bool do_is(mask m, char_type c) const {
        if ((m & digit) && jdigits.count(c))
            return true; // Japanese digits will be classified as digits
        return ctype::do_is(m, c); // leave the rest to the parent class
    }
};
 
int main()
{
 
    std::wstring text = L"123一二三123";
    std::locale loc(std::locale(""), new jdigit_ctype);
 
    std::locale::global(std::locale(""));
    std::wcout.imbue(std::locale());
 
    for(wchar_t c : text)
        if(std::isdigit(c, loc))
            std::wcout << c << " is a digit\n";
        else
            std::wcout << c << " is NOT a digit\n";
}

二次

产出:

二次

代码语言:javascript
复制
1 is a digit
2 is a digit
3 is a digit
一 is a digit
二 is a digit
三 is a digit
1 is NOT a digit
2 is NOT a digit
3 is NOT a digit

二次

另见

isdigit

checks if a character is a digit (function)

iswdigit

checks if a wide character is a digit (function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com