Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::locale::locale

      From cppreference.com
      <cpp‎ |locale‎ |locale
       
       
       
      Localization library
       
       
      (1)
      locale()throw();
      (until C++11)
      locale()noexcept;
      (since C++11)
      (2)
      locale(const locale& other)throw();
      (until C++11)
      locale(const locale& other)noexcept;
      (since C++11)
      explicit locale(constchar* std_name);
      (3)
      explicit locale(conststd::string& std_name);
      (4)(since C++11)
      locale(const locale& other,constchar* std_name, category cats);
      (5)
      locale(const locale& other,conststd::string& std_name, category cats);
      (6)(since C++11)
      template<class Facet>
      locale(const locale& other, Facet* f);
      (7)
      locale(const locale& other,const locale& one, category cats);
      (8)

      Constructs a new locale object.

      1) Default constructor. Constructs a copy of the global C++ locale, which is the locale most recently used as the argument tostd::locale::global or a copy ofstd::locale::classic() if no call tostd::locale::global has been made.
      2) Copy constructor. Constructs a copy ofother.
      3,4) Constructs a copy of the system locale with specifiedstd_name (such as"C", or"POSIX", or"en_US.UTF-8", or"English_US.1251"), if such locale is supported by the operating system. The locale constructed in this manner has a name.
      4) Equivalent tolocale(std_name.c_str()).
      5) Constructs a copy ofother except for all the facets identified by thecats argument, which are copied from the system locale identified by itsstd_name. The locale constructed in this manner has a name if and only ifother has a name.
      6) Equivalent tolocale(other, std_name.c_str(), cats).
      7) Constructs a copy ofother except for the facet of typeFacet (typically deduced from the type of the argument) which is installed fromf. Iff is a null pointer, the constructed locale is a full copy ofother. The program is ill-formed ifFacet is not afacet or it is a volatile-qualified facet.
      Iff is null, the constructed locale has the same name asother. Otherwise, the constructed locale has no name.
      8) Constructs a copy ofother except for all the facets identified by thecats argument, which are copied fromone.
      Ifcats is equal tolocale::none, the constructed locale has a name if and only ifother has a name. Otherwise, the constructed locale has a name if and only ifother andone both have names.

      Contents

      [edit]Parameters

      other - another locale to copy
      std_name - name of the system locale to use
      f - pointer to a facet to merge withother
      cats - the facet categories used to identify the facets to merge withother
      one - another locale to take facets from

      [edit]Exceptions

      3,5)std::runtime_error if the operating system has no locale namedstd_name or ifstd_name is a null pointer.
      4,6)std::runtime_error if the operating system has no locale namedstd_name.

      [edit]Notes

      Overload(7) is typically called with its second argument,f, obtained directly from a new-expression: the locale is responsible for calling the matchingdelete from its own destructor.

      [edit]Example

      Run this code
      #include <codecvt>#include <iostream>#include <locale> std::ostream& operator<<(std::ostream& os,conststd::locale& loc){if(loc.name().length()<=80)        os<< loc.name();elsefor(constauto c: loc.name())            os<< c<<(c==';'?"\n  ":""); return os<<'\n';} int main(){std::locale l1;std::cout<<"Name of a copy of the classic\"C\" locale: "<< l1; std::locale l2("en_US.UTF-8");std::cout<<"Name of unicode locale: "<< l2; std::locale l3(l1, newstd::codecvt_utf8<wchar_t>);std::cout<<"Name of\"C\" locale except for codecvt: "<< l3; std::locale l4(l1, l2, std::locale::ctype);std::cout<<"Name of\"C\" locale except for ctype, which is unicode:\n  "<< l4;}

      Possible output:

      Name of a copy of the classic "C" locale: CName of unicode locale: en_US.UTF-8Name of "C" locale except for codecvt: *Name of "C" locale except for ctype, which is unicode:  LC_CTYPE=en_US.UTF-8;  LC_NUMERIC=C;  LC_TIME=C;  LC_COLLATE=C;  LC_MONETARY=C;  LC_MESSAGES=C;  LC_PAPER=C;  LC_NAME=C;  LC_ADDRESS=C;  LC_TELEPHONE=C;  LC_MEASUREMENT=C;  LC_IDENTIFICATION=C

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 436C++98for overload(7), it was unclear
      whetherFacet can be cv-qualified
      it can be const-qualified,
      but not volatile-qualified
      LWG 2295C++98for overload(7), the constructed locale had no name even iff is nullit has the name ofother

      [edit]See also

      destructs the locale and the facets whose reference count becomes zero
      (public member function)[edit]

      [edit]External links

      1. List of Windows locale names.
      2. List of Linux locale names.
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/locale/locale&oldid=178561"

      [8]ページ先頭

      ©2009-2025 Movatter.jp