CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 20 Jul 2025 08:00:03 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/string/basic_string/
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 20 Jul 2025 08:00:04 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"cf8e-ldTd3QdojCAgax+KGYFVLF3jWXo"
Content-Encoding: gzip
The basic_string is the generalization of class string for any character type (see string for a description).
Note: Because the first template parameter is not aliased as any member type, charT is used throughout this reference to refer to this type.
Iterators:
Capacity:
Element access:
Modifiers:
String operations:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
basic_string
- basic_string::~basic_string
- basic_string::basic_string
member functions
- basic_string::append
- basic_string::assign
- basic_string::at
-
basic_string::backC++11
- basic_string::begin
- basic_string::c_str
- basic_string::capacity
-
basic_string::cbeginC++11
-
basic_string::cendC++11
- basic_string::clear
- basic_string::compare
- basic_string::copy
-
basic_string::crbeginC++11
-
basic_string::crendC++11
- basic_string::data
- basic_string::empty
- basic_string::end
- basic_string::erase
- basic_string::find
- basic_string::find_first_not_of
- basic_string::find_first_of
- basic_string::find_last_not_of
- basic_string::find_last_of
-
basic_string::frontC++11
- basic_string::get_allocator
- basic_string::insert
- basic_string::length
- basic_string::max_size
- basic_string::operator[]
- basic_string::operator+=
- basic_string::operator=
-
basic_string::pop_backC++11
- basic_string::push_back
- basic_string::rbegin
- basic_string::rend
- basic_string::replace
- basic_string::reserve
- basic_string::resize
- basic_string::rfind
-
basic_string::shrink_to_fitC++11
- basic_string::size
- basic_string::substr
- basic_string::swap
member constants
non-member overloads
class template
<string>
std::basic_string
template < class charT, class traits = char_traits<charT>, // basic_string::traits_type class Alloc = allocator<charT> // basic_string::allocator_type > class basic_string;
Generic string class
Template parameters
- charT
- Character type.
The string is formed by a sequence of characters of this type.
This shall be a non-array POD type. - traits
- Character traits class that defines essential properties of the characters used by basic_string objects (see char_traits).
traits::char_type shall be the same as charT.
Aliased as member type basic_string::traits_type. - Alloc
- Type of the allocator object used to define the storage allocation model. By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Aliased as member type basic_string::allocator_type.
Note: Because the first template parameter is not aliased as any member type, charT is used throughout this reference to refer to this type.
Template instantiations
- string
- String class (class)
- wstring
- Wide string (class)
- u16string
- String of 16-bit characters (class)
- u32string
- String of 32-bit characters (class)
Member types
member type | definition | notes |
---|---|---|
traits_type | The second template parameter (traits) | defaults to: char_traits<charT> |
allocator_type | The third template parameter (Alloc) | defaults to: allocator<charT> |
value_type | traits_type::char_type | shall be the same as charT |
reference | allocator_type::reference | for the default allocator: charT& |
const_reference | allocator_type::const_reference | for the default allocator: const charT& |
pointer | allocator_type::pointer | for the default allocator: charT* |
const_pointer | allocator_type::const_pointer | for the default allocator: const charT* |
iterator | a random access iterator to charT | convertible to const_iterator |
const_iterator | a random access iterator to const charT | |
reverse_iterator | reverse_iterator<iterator> | |
const_reverse_iterator | reverse_iterator<const_iterator> | |
difference_type | allocator_type::difference_type | usually the same as ptrdiff_t |
size_type | allocator_type::size_type | usually the same as size_t |
member type | definition | notes |
---|---|---|
traits_type | The second template parameter (traits) | defaults to: char_traits<charT> |
allocator_type | The third template parameter (Alloc) | defaults to: allocator<charT> |
value_type | traits_type::char_type | shall be the same as charT |
reference | value_type& | |
const_reference | const value_type& | |
pointer | allocator_traits<allocator_type>::pointer | for the default allocator: charT* |
const_pointer | allocator_traits<allocator_type>::const_pointer | for the default allocator: const charT* |
iterator | a random access iterator to charT | convertible to const_iterator |
const_iterator | a random access iterator to const charT | |
reverse_iterator | reverse_iterator<iterator> | |
const_reverse_iterator | reverse_iterator<const_iterator> | |
difference_type | allocator_traits<allocator_type>::difference_type | usually the same as ptrdiff_t |
size_type | allocator_traits<allocator_type>::size_type | usually the same as size_t |
Member functions
- (constructor)
- Construct basic_string object (public member function)
- (destructor)
- String destructor (public member function)
- operator=
- String assignment (public member function)
Iterators:
- begin
- Return iterator to beginning (public member function)
- end
- Return iterator to end (public member function)
- rbegin
- Return reverse iterator to reverse beginning (public member function)
- rend
- Return reverse iterator to reverse end (public member function)
- cbegin
- Return const_iterator to beginning (public member function)
- cend
- Return const_iterator to end (public member function)
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function)
- crend
- Return const_reverse_iterator to reverse end (public member function)
Capacity:
- size
- Return size (public member function)
- length
- Return length of string (public member function)
- max_size
- Return maximum size (public member function)
- resize
- Resize string (public member function)
- capacity
- Return size of allocated storage (public member function)
- reserve
- Request a change in capacity (public member function)
- clear
- Clear string (public member function)
- empty
- Test whether string is empty (public member function)
- shrink_to_fit
- Shrink to fit (public member function)
Element access:
- operator[]
- Get character of string (public member function)
- at
- Get character of string (public member function)
- back
- Access last character (public member function)
- front
- Access first character (public member function)
Modifiers:
- operator+=
- Append to string (public member function)
- append
- Append to string (public member function)
- push_back
- Append character to string (public member function)
- assign
- Assign content to string (public member function)
- insert
- Insert into string (public member function)
- erase
- Erase characters from string (public member function)
- replace
- Replace portion of string (public member function)
- swap
- Swap string values (public member function)
- pop_back
- Delete last character (public member function)
String operations:
- c_str
- Get C-string equivalent
- data
- Get string data (public member function)
- get_allocator
- Get allocator (public member function)
- copy
- Copy sequence of characters from string (public member function)
- find
- Find first occurrence in string (public member function)
- rfind
- Find last occurrence in string (public member function)
- find_first_of
- Find character in string (public member function)
- find_last_of
- Find character in string from the end (public member function)
- find_first_not_of
- Find non-matching character in string (public member function)
- find_last_not_of
- Find non-matching character in string from the end (public member function)
- substr
- Generate substring (public member function)
- compare
- Compare strings (public member function)
Non-member function overloads
- operator+
- Concatenate strings (function template)
- relational operators
- Relational operators for basic_string (function template)
- swap
- Exchanges the values of two strings (function template)
- operator>>
- Extract string from stream (function template)
- operator<<
- Insert string into stream (function template)
- getline
- Get line from stream into string (function template)
Member constants
- npos
- Maximum value of size_type (public static member constant)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us