Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string"

From cppreference.com
< cpp
m (r2.7.3) (Robot: Adding de:cpp/string)
(added a bit of structure and narrative)
Line 2: Line 2:
 
{{cpp/string/sidebar}}
 
{{cpp/string/sidebar}}
  
==={{rl | byte | Null-terminated byte string management}} ===
+
The C++ string library includes support for two general types of strings:
  
==={{rl | multibyte | Null-terminated multibyte string management}} ===
+
* {{c|std::basic_string}} - a templated class that encapsulates common string operations
 +
* Null-terminated strings - arrays of characters terminated by a special token
  
==={{rl | wide| Null-terminated wide string management}}===
+
=== {{c|std::basic_string}} ===
  
==={{rl | basic_string}}===
+
The templated class {{c|std::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 friend functions.
  
{{ddcl | header=string | 1=
+
Several specializations of {{c|std::basic_string}} are provided for commonly-used types:
template<
+
    class CharT,
+
    class Traits = std::char_traits<CharT>,
+
    class Allocator = std::allocator<CharT> >
+
> class basic_string;
+
}}
+
 
+
The class {{rlt|basic_string}} generalizes the way how sequences of characters are manipulated and stored.
+
 
+
Several specializations of the class {{tt|basic_string}} are provided:
+
  
 
{{tdcl list begin}}
 
{{tdcl list begin}}
 
{{tdcl list header | string}}
 
{{tdcl list header | string}}
 
{{tdcl list hitem | Type | Definition}}
 
{{tdcl list hitem | Type | Definition}}
{{tdcl list item | {{tt|string}} | {{c|basic_string<char>}}}}
+
{{tdcl list item | {{c|std::string}} | {{c|std::basic_string<char>}}}}
{{tdcl list item | {{tt|wstring}} | {{c|basic_string<wchar_t>}}}}
+
{{tdcl list item | {{c|std::wstring}} | {{c|std::basic_string<wchar_t>}}}}
{{tdcl list item | {{tt|u16string}} | {{c|basic_string<char16_t>}} | notes={{mark since c++11}}}}
+
{{tdcl list item | {{c|std::u16string}} | {{c|std::basic_string<char16_t>}} | notes={{mark since c++11}}}}
{{tdcl list item | {{tt|u32string}} | {{c|basic_string<char32_t>}} | notes={{mark since c++11}}}}
+
{{tdcl list item | {{c|std::u32string}} | {{c|std::basic_string<char32_t>}} | notes={{mark since c++11}}}}
 
{{tdcl list end}}
 
{{tdcl list end}}
  
==={{rl| char_traits}}===
+
=== Null-terminated strings ===
 +
 
 +
Null-terminated strings are arrays of characters that are terminated by a special token.  C++ provides functions to create, inspect, and modify null-terminated strings.
 +
 
 +
There are three types of null-terminated strings:
 +
 
 +
* {{rl | byte | null-terminated byte strings}}
 +
* {{rl | multibyte | null-terminated multibyte strings}}
 +
* {{rl | wide | null-terminated wide strings}}
 +
 
 +
=== Additional support ===
 +
 
 +
===={{rl| char_traits}}====
  
Strings library provides class template {{rlt|char_traits}}, defining types and functions for a character container. The following specializations are defined:
+
The string library also provides class template {{rlt|char_traits}} that defines types and functions for {{c|std::basic_string}}. The following specializations are defined:
  
 
{{ddcl list begin}}
 
{{ddcl list begin}}

Revision as of 07:08, 9 May 2012

Template:cpp/string/sidebar

The C++ string library includes support for two general types of strings:

  • std::basic_string - a templated class that encapsulates common string operations
  • Null-terminated strings - arrays of characters terminated by a special token

Contents

std::basic_string

The templated class std::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 friend functions.

Several specializations of std::basic_string are provided for commonly-used types:

Template:tdcl list begin Template:tdcl list header Template:tdcl list hitem Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list item Template:tdcl list end

Null-terminated strings

Null-terminated strings are arrays of characters that are terminated by a special token. C++ provides functions to create, inspect, and modify null-terminated strings.

There are three types of null-terminated strings:

Additional support

char_traits

The string library also provides class template char_traits that defines types and functions for std::basic_string. The following specializations are defined:

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <string>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template<> class char_traits<std::string>;

template<> class char_traits<std::wstring>;
template<> class char_traits<std::u16string>;

template<> class char_traits<std::u32string>;
</td>

<td class="t-dcl-nopad"> </td> <td >

(since C++11)
(since C++11) </td> </tr> Template:ddcl list end