Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::numpunct<CharT>::truename, do_truename, falsename, do_falsename

      From cppreference.com
      <cpp‎ |locale‎ |numpunct
       
       
       
      Localization library
       
       
      Defined in header<locale>
      public:
      string_type truename()const;
      (1)
      public:
      string_type falsename()const;
      (2)
      protected:
      virtual string_type do_truename()const;
      (3)
      protected:
      virtual string_type do_falsename()const;
      (4)
      1,2) Public member function, calls the member functiondo_truename anddo_falsename of the most derived class respectively.
      3) Returns the string to be used as the representation of the boolean valuetrue.
      4) Returns the string to be used as the representation of the boolean valuefalse.

      [edit]Return value

      1,3) The object of typestring_type to use as the representation oftrue. The standard specializations ofstd::numpunct return"true" andL"true".
      2,4) The object of typestring_type to use as the representation offalse. The standard specializations ofstd::numpunct return"false" andL"false".

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <locale> struct custom_tf:std::numpunct<char>{std::string do_truename()const{return{'t'};}std::string do_falsename()const{return{'f'};}}; int main(){std::cout<<std::boolalpha; // default boolalpha outputstd::cout<<"Default locale,\n""  boolalpha  true: "<<true<<"\n""  boolalpha false: "<<false<<"\n\n"; // with custom_tf applied to localestd::cout.imbue(std::locale(std::cout.getloc(), new custom_tf));std::cout<<"Locale with modified numpunct,\n""  boolalpha  true: "<<true<<"\n""  boolalpha false: "<<false<<'\n';}

      Output:

      Default locale,  boolalpha  true: true  boolalpha false: false Locale with modified numpunct,  boolalpha  true: t  boolalpha false: f
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/numpunct/truefalsename&oldid=179591"

      [8]ページ先頭

      ©2009-2026 Movatter.jp