Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string"

From cppreference.com
< cpp
m (r2.7.3) (Robot: Adding ar, es, fr, it, ja, pt, ru, zh)
m (Shorten template names. Use {{lc}} where appropriate.)
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 designed to manipulate strings of any character type.
+
* {{lc|std::basic_string}} - a templated class designed to manipulate strings of any character type.
 
* Null-terminated strings - arrays of characters terminated by a special ''null'' character.
 
* Null-terminated strings - arrays of characters terminated by a special ''null'' character.
  
=== {{c|std::basic_string}} ===
+
=== {{lc|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 related functions.
+
The templated class {{lc|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 {{lc|std::basic_string}} are provided for commonly-used types:
  
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list header | string}}
+
{{dsc header | string}}
{{dcl list hitem | Type | Definition}}
+
{{dsc hitem | Type | Definition}}
{{dcl list item | {{c|std::string}} | {{c|std::basic_string<char>}}}}
+
{{dsc | {{lc|std::string}} | {{c|std::basic_string<char>}}}}
{{dcl list item | {{c|std::wstring}} | {{c|std::basic_string<wchar_t>}}}}
+
{{dsc | {{lc|std::wstring}} | {{c|std::basic_string<wchar_t>}}}}
{{dcl list item | {{c|std::u16string}} | {{c|std::basic_string<char16_t>}} | notes={{mark since c++11}}}}
+
{{dsc | {{lc|std::u16string}} | {{c|std::basic_string<char16_t>}} | notes={{mark since c++11}}}}
{{dcl list item | {{c|std::u32string}} | {{c|std::basic_string<char32_t>}} | notes={{mark since c++11}}}}
+
{{dsc | {{lc|std::u32string}} | {{c|std::basic_string<char32_t>}} | notes={{mark since c++11}}}}
{{dcl list end}}
+
{{dsc end}}
  
 
=== Null-terminated strings ===
 
=== Null-terminated strings ===
Line 36: Line 36:
 
===={{rl| char_traits}}====
 
===={{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:
+
The string library also provides class template {{rlt|char_traits}} that defines types and functions for {{lc|std::basic_string}}. The following specializations are defined:
  
{{ddcl list begin}}
+
{{dcl begin}}
{{ddcl list header | string}}
+
{{dcl header | string}}
{{ddcl list item | notes=<br><br>{{mark since c++11}}<br>{{mark since c++11}} |
+
{{dcl | notes=<br><br>{{mark since c++11}}<br>{{mark since c++11}} |
 
template<> class char_traits<std::string>;
 
template<> class char_traits<std::string>;
 
template<> class char_traits<std::wstring>;
 
template<> class char_traits<std::wstring>;
Line 46: Line 46:
 
template<> class char_traits<std::u32string>;
 
template<> class char_traits<std::u32string>;
 
}}
 
}}
{{ddcl list end}}
+
{{dcl end}}
  
 
[[ar:cpp/string]]
 
[[ar:cpp/string]]

Revision as of 19:53, 31 May 2013

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 null character.

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 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:

Defined in header <string>
template<> class char_traits<std::string>;

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

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


(since C++11)
(since C++11)