##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Strings library

From cppreference.com
< cpp

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.

### [edit] 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>

### [edit] 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:

- null-terminated byte strings
- null-terminated multibyte strings
- null-terminated wide strings

### [edit] Additional support

#### [edit] std::char_traits

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

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string&oldid=67390"