std::basic_string

From cppreference.com
 
 
 
std::basic_string
Member functions
basic_string::basic_string
basic_string::operator=
basic_string::assign
basic_string::get_allocator
Element access
basic_string::at
basic_string::operator[]
basic_string::front (C++11)
basic_string::back (C++11)
basic_string::data
basic_string::c_str
Iterators
basic_string::begin
basic_string::cbegin

(C++11)
basic_string::end
basic_string::cend

(C++11)
basic_string::rbegin
basic_string::crbegin

(C++11)
basic_string::rend
basic_string::crend

(C++11)
Capacity
basic_string::empty
basic_string::size
basic_string::length
basic_string::max_size
basic_string::reserve
basic_string::capacity
basic_string::shrink_to_fit (C++11)
Operations
basic_string::clear
basic_string::insert
basic_string::erase
basic_string::push_back
basic_string::pop_back (C++11)
basic_string::append
basic_string::operator+=
basic_string::compare
basic_string::replace
basic_string::substr
basic_string::copy
basic_string::resize
basic_string::swap
Search
basic_string::find
basic_string::rfind
basic_string::find_first_of
basic_string::find_first_not_of
basic_string::find_last_of
basic_string::find_last_not_of
Constants
basic_string::npos
Non-member functions
operator+
operator==
operator!=
operator<
operator>
operator<=
operator>=
swap(std::basic_string)
operator<<
operator>>
getline
stoi
stol
stoll
(C++11)
(C++11)
(C++11)
stoul
stoull
(C++11)
(C++11)
stof
stod
stold
(C++11)
(C++11)
(C++11)
to_string (C++11)
to_wstring (C++11)
Helper classes
hash<std::string>
hash<std::wstring>
hash<std::u32string>
hash<std::u16string>
(C++11)
 
Defined in header <string>
template<

    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>

> class basic_string;

The class template basic_string stores and manipulates sequences of char-like objects (that is, objects for which a specialization of std::char_traits or compatible traits class is provided).

The elements of a basic_string are stored contiguously, that is, for a basic_string s, &*(s.begin() + n) == &*s.begin() + n for any n in [0, s.size()), or, equivalently, a pointer to s[0] can be passed to functions that expect a pointer to the first element of a CharT[] array.

(since C++11)

Several specializations for common character types are provided:

Defined in header <string>
Type Definition
std::string std::basic_string<char>
std::wstring std::basic_string<wchar_t>
std::u16string (C++11) std::basic_string<char16_t>
std::u32string (C++11) std::basic_string<char32_t>

Contents

[edit] Member types

Member type Definition
traits_type Traits
value_type Traits::char_type
allocator_type Allocator
size_type Unsigned integral type (usually size_t)
difference_type Signed integer type (usually ptrdiff_t)
reference Allocator::reference (until C++11)
value_type& (since C++11)
const_reference Allocator::const_reference (until C++11)
const value_type& (since C++11)
pointer Allocator::pointer (until C++11)
std::allocator_traits<Allocator>::pointer (since C++11)
const_pointer Allocator::const_pointer (until C++11)
std::allocator_traits<Allocator>::const_pointer (since C++11)
iterator RandomAccessIterator
const_iterator Constant random access iterator
reverse_iterator std::reverse_iterator<iterator>
const_reverse_iterator std::reverse_iterator<const_iterator>

[edit] Member functions

constructs a basic_string
(public member function)
assigns values to the string
(public member function)
assign characters to a string
(public member function)
returns the associated allocator
(public member function)
Element access
access specified character with bounds checking
(public member function)
access specified character
(public member function)
(C++11)
accesses the first character
(public member function)
(C++11)
accesses the last character
(public member function)
returns a pointer to the first character of a string
(public member function)
returns a non-modifiable standard C character array version of the string
(public member function)
Iterators

(C++11)
returns an iterator to the beginning
(public member function)

(C++11)
returns an iterator to the end
(public member function)
returns a reverse iterator to the beginning
(public member function)

(C++11)
returns a reverse iterator to the end
(public member function)
Capacity
checks whether the string is empty
(public member function)
returns the number of characters
(public member function)
returns the maximum number of characters
(public member function)
reserves storage
(public member function)
returns the number of characters that can be held in currently allocated storage
(public member function)
reduces memory usage by freeing unused memory
(public member function)
Operations
clears the contents
(public member function)
inserts characters
(public member function)
removes characters
(public member function)
appends a character to the end
(public member function)
(C++11)
removes the last character
(public member function)
appends characters to the end
(public member function)
appends characters to the end
(public member function)
compares two strings
(public member function)
replaces specified portion of a string
(public member function)
returns a substring
(public member function)
copies characters
(public member function)
changes the number of characters stored
(public member function)
swaps the contents
(public member function)
Search
find characters in the string
(public member function)
find the last occurrence of a substring
(public member function)
find first occurrence of characters
(public member function)
find first absence of characters
(public member function)
find last occurrence of characters
(public member function)
find last absence of characters
(public member function)

Constants

[static]
special value. The exact meaning depends on the context
(public static member constant)

[edit] Non-member functions

concatenates two strings or a string and a char
(function template)
lexicographically compares two strings
(function template)
specializes the std::swap algorithm
(function template)
Input/output
performs stream I/O on strings
(function template)
read data from an I/O stream into a string
(function)
Numeric conversions
(C++11)
(C++11)
(C++11)
converts a string to an signed integer
(function)
(C++11)
(C++11)
converts a string to an unsigned integer
(function)
(C++11)
(C++11)
(C++11)
converts a string to an floating point value
(function)
(C++11)
converts an integral or floating point value to string
(function)
(C++11)
converts an integral or floating point value to wstring
(function)

[edit] Helper classes

hash support for strings
(class template specialization)