Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ctype

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
       
      Defined in header<locale>
      template<class CharT>
      class ctype;

      Classctype encapsulates character classification features. All stream input operations performed throughstd::basic_istream<CharT> use thestd::ctype<CharT> of the locale imbued in the stream to identify whitespace characters for input tokenization. Stream output operations applystd::ctype<CharT>::widen() to narrow-character arguments prior to output.

      std-ctype-inheritance.svg

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide the following specializations (they arerequired to be implemented by any locale object):

      Defined in header<locale>
      std::ctype<char> provides narrow character equivalents of the minimal "C" locale classification. This specialization uses table lookup for character classification
      std::ctype<wchar_t> provides wide character classification appropriate to the native character set

      [edit]Nested types

      Type Definition
      char_typeCharT

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      [edit]Member functions

      constructs a newctype facet
      (public member function)
      destructs actype facet
      (protected member function)
      invokesdo_is
      (public member function)[edit]
      invokesdo_scan_is
      (public member function)[edit]
      invokesdo_scan_not
      (public member function)[edit]
      invokesdo_toupper
      (public member function)[edit]
      invokesdo_tolower
      (public member function)[edit]
      invokesdo_widen
      (public member function)[edit]
      invokesdo_narrow
      (public member function)[edit]

      [edit]Protected member functions

      [virtual]
      classifies a character or a character sequence
      (virtual protected member function)[edit]
      [virtual]
      locates the first character in a sequence that conforms to given classification
      (virtual protected member function)[edit]
      [virtual]
      locates the first character in a sequence that fails given classification
      (virtual protected member function)[edit]
      [virtual]
      converts a character or characters to uppercase
      (virtual protected member function)[edit]
      [virtual]
      converts a character or characters to lowercase
      (virtual protected member function)[edit]
      [virtual]
      converts a character or characters fromchar toCharT
      (virtual protected member function)[edit]
      [virtual]
      converts a character or characters fromCharT tochar
      (virtual protected member function)[edit]

      Inherited fromstd::ctype_base

      Nested types

      Type Definition
      mask unspecifiedBitmaskType type (enumeration, integer type, or bitset)

      Member constants

      space
      [static]
      the value ofmask identifying whitespace character classification
      (public static member constant)
      print
      [static]
      the value ofmask identifying printable character classification
      (public static member constant)
      cntrl
      [static]
      the value ofmask identifying control character classification
      (public static member constant)
      upper
      [static]
      the value ofmask identifying uppercase character classification
      (public static member constant)
      lower
      [static]
      the value ofmask identifying lowercase character classification
      (public static member constant)
      alpha
      [static]
      the value ofmask identifying alphabetic character classification
      (public static member constant)
      digit
      [static]
      the value ofmask identifying digit character classification
      (public static member constant)
      punct
      [static]
      the value ofmask identifying punctuation character classification
      (public static member constant)
      xdigit
      [static]
      the value ofmask identifying hexadecimal digit character classification
      (public static member constant)
      blank
      [static](C++11)
      the value ofmask identifying blank character classification
      (public static member constant)
      alnum
      [static]
      alpha| digit
      (public static member constant)
      graph
      [static]
      alnum| punct
      (public static member constant)

      [edit]Example

      The following example demonstrates modification of actype other thanctype<char> to tokenize a CSV file:

      Run this code
      #include <iostream>#include <locale>#include <sstream> struct csv_whitespace: std::ctype<wchar_t>{bool do_is(mask m, char_type c)const{if((m& space)&& c== L' ')returnfalse;// space will NOT be classified as whitespace if((m& space)&& c== L',')returntrue;// comma will be classified as whitespace return ctype::do_is(m, c);// leave the rest to the base class}}; int main(){std::wstring in= L"Column 1,Column 2,Column 3\n123,456,789";std::wstring token; std::wcout<<"default locale:\n";std::wistringstream s1(in);while(s1>> token)std::wcout<<"  "<< token<<'\n'; std::wcout<<"locale with modified ctype:\n";std::wistringstream s2(in);    csv_whitespace* my_ws= new csv_whitespace;    s2.imbue(std::locale(s2.getloc(), my_ws));while(s2>> token)std::wcout<<"  "<< token<<'\n';}

      Output:

      default locale:  Column  1,Column  2,Column  3  123,456,789locale with modified ctype:  Column 1  Column 2  Column 3  123  456  789

      [edit]See also

      specialization ofstd::ctype for typechar
      (class template specialization)[edit]
      defines character classification categories
      (class)[edit]
      represents the system-suppliedstd::ctype for the named locale
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/ctype&oldid=177710"

      [8]ページ先頭

      ©2009-2025 Movatter.jp