Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string"

From cppreference.com
< cpp
m (Text replace - "/sidebar" to "/navbar")
(several improvements)
Line 4: Line 4:
 
The C++ strings library includes support for two general types of strings:
 
The C++ strings library includes support for two general types of strings:
  
* {{c|std::basic_string}} - a templated class that encapsulates common string operations
+
* {{c|std::basic_string}} - a templated class designed to manipulate strings of any character type.
* Null-terminated strings - arrays of characters terminated by a special token
+
* Null-terminated strings - arrays of characters terminated by a special character called ''null'' charater.
  
 
=== {{c|std::basic_string}} ===
 
=== {{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.
+
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 related functions.
  
 
Several specializations of {{c|std::basic_string}} are provided for commonly-used types:
 
Several specializations of {{c|std::basic_string}} are provided for commonly-used types:
Line 24: Line 24:
 
=== Null-terminated strings ===
 
=== 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.
+
Null-terminated strings are arrays of characters that are terminated by a special character, called ''null'' character.  C++ provides functions to create, inspect, and modify null-terminated strings.
  
 
There are three types of null-terminated strings:
 
There are three types of null-terminated strings:

Revision as of 05:09, 7 August 2012

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

  • std::basic_string - a templated class designed to manipulate strings of any character type.
  • Null-terminated strings - arrays of characters terminated by a special character called null charater.

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 related functions.

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

Defined in header <string>
Type Definition
std::string std::basic_string<char>
std::wstring std::basic_string<wchar_t>
std::u16string std::basic_string<char16_t>
std::u32string std::basic_string<char32_t>

Null-terminated strings

Null-terminated strings are arrays of characters that are terminated by a special character, called null character. 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