Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Strings library

      From cppreference.com
      <cpp
       
       
       

      Contents

      [edit]Characters

      In the C++ standard library, acharacter is an object which, when treated sequentially, can represent text.

      The term means not only objects ofcharacter types, but also any value that can be represented by a type that provides the definitions specified in the strings library and following libraries:

      (since C++11)

      In the strings library and regular expressions library(since C++11), a character can be of onlychar-like types, i.e. those non-array types that satisfy the requirements ofPODType(until C++20)TrivialType andStandardLayoutType(since C++20)(until C++26)TriviallyCopyable andStandardLayoutType(since C++26).

      For any char-like typeT,std::is_trivially_default_constructible_v<T> istrue.

      (since C++26)

      Therefore, characters are also referred aschar-like objects in the strings library and regular expressions library(since C++11).

      Some standard library components acceptcharacter container types. They, too, are types used to represent individual characters. Such types are used for one of the template arguments ofstd::char_traits and the class templates which usestd::char_traits.

      [edit]Library components

      The C++ strings library includes the following components:

      [edit]Character traits

      Many character-related class templates (such asstd::basic_string) need a set of related types and functions to complete the definition of their semantics. These types and functions are provided as a set of membertypedef names and functions in the template parameterTraits used by each such template. The classes which are able to complete those semantics areCharTraits.

      The string library provides the class templatestd::char_traits that defines types and functions forstd::basic_string andstd::basic_string_view(since C++17).

      The following specializations are defined, all of them satisfy theCharTraits requirements:

      Defined in header<string>
      template<>class char_traits<char>;
      template<>class char_traits<wchar_t>;
      template<>class char_traits<char8_t>;
      (since C++20)
      template<>class char_traits<char16_t>;
      (since C++11)
      template<>class char_traits<char32_t>;
      (since C++11)

      When a user-defined character container type forstd::basic_string andstd::basic_string_view(since C++17) is used, it is also necessary to provide a corresponding character trait class (which can be a specialization ofstd::char_traits).

      [edit]String classes (std::string etc.)

      The class templatestd::basic_string generalizes how sequences of characters are manipulated and stored. String creation, manipulation, and destruction are all handled by a convenient set of class methods and related functions.

      Several specializations ofstd::basic_string are provided for commonly-used types:

      Defined in header<string>
      Type Definition
      std::stringstd::basic_string<char>
      std::wstringstd::basic_string<wchar_t>
      std::u8string(since C++20)std::basic_string<char8_t>
      std::u16string(since C++11)std::basic_string<char16_t>
      std::u32string(since C++11)std::basic_string<char32_t>

      [edit]String view classes (std::string_view etc.)(since C++17)

      The class templatestd::basic_string_view provides a lightweight object that offers read-only access to a string or a part of a string using an interface similar to the interface ofstd::basic_string.

      Several specializations ofstd::basic_string_view are provided for commonly-used types:

      Defined in header<string_view>
      Type Definition
      std::string_viewstd::basic_string_view<char>
      std::wstring_viewstd::basic_string_view<wchar_t>
      std::u8string_view(since C++20)std::basic_string_view<char8_t>
      std::u16string_viewstd::basic_string_view<char16_t>
      std::u32string_viewstd::basic_string_view<char32_t>

      [edit]Relevant libraries

      Thetext processing library provides support for localizations, string conversions (e.g.std::toupper), character classification functions (e.g.std::isspace), and text encoding recognition (std::text_encoding).

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 1170C++98char-like types could be array typesprohibited

      [edit]See also

      C documentation forStrings library
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string&oldid=179902"

      [8]ページ先頭

      ©2009-2025 Movatter.jp