Difference between revisions of "cpp/string"
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}} | ||
− | + | The C++ string library includes support for two general types of strings: | |
− | + | * {{c|std::basic_string}} - a templated class that encapsulates common string operations | |
+ | * Null-terminated strings - arrays of characters terminated by a special token | ||
− | ==={{ | + | === {{c|std::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. | |
− | {{ | + | Several specializations of {{c|std::basic_string}} are provided for commonly-used types: |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
{{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 | {{ | + | {{tdcl list item | {{c|std::string}} | {{c|std::basic_string<char>}}}} |
− | {{tdcl list item | {{ | + | {{tdcl list item | {{c|std::wstring}} | {{c|std::basic_string<wchar_t>}}}} |
− | {{tdcl list item | {{ | + | {{tdcl list item | {{c|std::u16string}} | {{c|std::basic_string<char16_t>}} | notes={{mark since c++11}}}} |
− | {{tdcl list item | {{ | + | {{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}}==== | ||
− | + | 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
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><string>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td >template<> class char_traits<std::wstring>;
template<> class char_traits<std::u16string>;
<td class="t-dcl-nopad"> </td>
<td >
(since C++11)
(since C++11) </td>
</tr>
Template:ddcl list end