Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::isdigit(std::locale)

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
      Defined in header<locale>
      template<class CharT>
      bool isdigit( CharT ch,const locale& loc);

      Checks if the given character is classified as a digit by the given locale'sstd::ctype facet.

      Contents

      [edit]Parameters

      ch - character
      loc - locale

      [edit]Return value

      Returnstrue if the character is classified as a digit,false otherwise.

      [edit]Possible implementation

      template<class CharT>bool isdigit(CharT ch,conststd::locale& loc){returnstd::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::digit, ch);}

      [edit]Example

      Run this code
      #include <iostream>#include <locale>#include <string>#include <unordered_set> struct jdigit_ctype:std::ctype<wchar_t>{std::unordered_set<wchar_t> jdigits{        L'一', L'二', L'三', L'四', L'五', L'六', L'七', L'八', L'九', L'十'}; bool do_is(mask m, char_type c)const override{return(m& digit)&& jdigits.contains(c)?true// Japanese digits will be classified as digits: 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("en_US.utf8"));std::wcout.imbue(std::locale()); for(constwchar_t c: text)if(std::isdigit(c, loc))std::wcout<< c<<" is a digit\n";elsestd::wcout<< c<<" is NOT a digit\n";}

      Possible output:

      1 is a digit2 is a digit3 is a digit一 is a digit二 is a digit三 is a digit1 is NOT a digit2 is NOT a digit3 is NOT a digit

      [edit]See also

      checks if a character is a digit
      (function)[edit]
      checks if a wide character is a digit
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/isdigit&oldid=160122"

      [8]ページ先頭

      ©2009-2025 Movatter.jp