String class
String objects are a special type of container, specifically designed to operate with sequences of characters.Unlike traditional c-strings, which are mere sequences of characters in a memory array, C++ string objects belong to a class with many built-in features to operate with strings in a more intuitive way and with some additional useful features common to C++ containers.
The string class is an instantiation of the basic_string class template, defined in <string> as:
typedef basic_string<char> string;
Member functions
(constructor) | Construct string object (constructor member ) |
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) |
Capacity:
size | Return length of string (public member function) |
length | Return length of string (public member function) |
max_size | Return maximum size of string (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 if string is empty (public member function) |
Element access:
operator[] | Get character in string (public member function) |
at | Get character in string (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 part of string (public member function ) |
swap | Swap contents with another string (public member function) |
String operations:
c_str | Get C string equivalent (public member function ) |
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 content in string (public member function) |
rfind | Find last occurrence of content 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 absence of character in string |
find_last_not_of | Find absence of character in string from the end (public member function) |
substr | Generate substring (public member function) |
compare | Compare strings (public member function ) |