A String is a sequence of characters. The standard string class provides interface similar to standard byte container, but adding features specifically designed to operate with strings of single-byte characters.
The string class is an instantiation of the basic_string class template that uses char (i.e., bytes) as its character type.
Syntax
typedef basic_string<char> string;
The C++ string container has a number of member functions which are listed below:
Functions | Description |
empty() | Checks whether the string is empty or not. |
length() | Returns the length of the string in terms of bytes. |
size() | Returns the length of the string in terms of bytes. |
resize() | Changes the size of the string to a length of specified number of characters. |
max_size() | Returns the maximum length of the string. |
clear() | Clears all characters of the string. |
capacity() | Returns size of allocated space to the string. |
shrink_to_fit() | Reduces the capacity of the string equal to fit its size. |
reserve() | Requests to reserve the string capacity be at least enough to contain n characters. |
Functions | Description |
at() | Access a character of the string. |
operator[]() | Access a character of the string. |
front() | Access first character of the string. |
back() | Access last character of the string. |
Functions | Description |
begin() | Returns iterator pointing to the first character of the string. |
end() | Returns iterator pointing to the past-the-last character of the string. |
rbegin() | Returns reverse iterator to the last character of the string. |
rend() | Returns reverse iterator to the character preceding the first character of the string. |
cbegin() | Returns const_iterator pointing to the first character of the string. |
cend() | Returns const_iterator pointing to the past-the-last character of the string. |
crbegin() | Returns const_reverse_iterator to the last character of the string. |
crend() | Returns const_reverse_iterator to the character preceding the first character of the string. |
Functions | Description |
pop_back() | Deletes last character of the string. |
push_back() | Adds a new character at the end of the string. |
swap() | Exchanges content of two strings. |
Functions | Description |
compare() | Compares two string objects. |
Functions | Description |
swap() | Exchanges content of two strings. |