The C++ Standard Library
- C++ Library - <valarray>
- C++ Library - <utility>
- C++ Library - <typeinfo>
- C++ Library - <tuple>
- C++ Library - <thread>
- C++ Library - <string>
- C++ Library - <stdexcept>
- C++ Library - <regex>
- C++ Library - <numeric>
- C++ Library - <new>
- C++ Library - <memory>
- C++ Library - <locale>
- C++ Library - <limits>
- C++ Library - <functional>
- C++ Library - <exception>
- C++ Library - <complex>
- C++ Library - <atomic>
- C++ Library - <streambuf>
- C++ Library - <sstream>
- C++ Library - <ostream>
- C++ Library - <istream>
- C++ Library - <iostream>
- C++ Library - <iosfwd>
- C++ Library - <ios>
- C++ Library - <iomanip>
- C++ Library - <fstream>
- C++ Library - Home
The C++ STL Library
- C++ Library - <iterator>
- C++ Library - <algorithm>
- C++ Library - <vector>
- C++ Library - <unordered_set>
- C++ Library - <unordered_map>
- C++ Library - <stack>
- C++ Library - <set>
- C++ Library - <queue>
- C++ Library - <map>
- C++ Library - <list>
- C++ Library - <forward_list>
- C++ Library - <deque>
- C++ Library - <bitset>
- C++ Library - <array>
C++ Programming Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
C++ Library - <string>
Introduction
String is a class and all objects that in string represent sequences of characters.
Declaration
Following is the declaration for std::string.
typedef basic_string<char> string;
C++11
typedef basic_string<char> string;
Member types
member type | definition |
---|---|
value_type | char |
traits_type | char_traits<char> |
allocator_type | allocator<char> |
reference | char& |
const_reference | const char& |
pointer | char* |
const_pointer | const char* |
iterator | a random access iterator to char (convertible to const_iterator) |
const_iterator | a random access iterator to const char |
reverse_iterator | reverse_iterator<iterator> |
const_reverse_iterator | reverse_iterator<const_iterator> |
difference_type | ptrdiff_t |
size_type | size_t |
Member functions
Sr.No. | Member function & description |
---|---|
1 | It constructs string object. |
2 | It is a string destructor. |
3 | It is a string assignment. |
Iterators
Sr.No. | Iterator & description |
---|---|
1 | It returns iterator to beginning. |
2 | It returns iterator to end. |
3 | It returns reverse iterator to reverse beginning. |
4 | It returns reverse iterator to reverse end. |
5 | It returns const_iterator to beginning. |
6 | It returns a const_iterator pointing to the past-the-end character of the string. |
7 | It returns const_reverse_iterator to reverse beginning. |
8 | It returns const_reverse_iterator to reverse end. |
Capacity
Sr.No. | Capacity & description |
---|---|
1 | It returns length of string. |
2 | It returns length of string. |
3 | It returns maximum size of string. |
4 | It resizes string. |
5 | It returns size of allocated storage. |
6 | It requests a change in capacity. |
7 | It clears the string. |
8 | It is used to test if string is empty. |
9 | It is used to shrink to fit. |
Capacity
Sr.No. | Element acce & description |
---|---|
1 | It is used to get character of string. |
2 | It is used to get character in string. |
3 | It is used to access last character. |
4 | It is used to access first character. |
Modifiers
Sr.No. | Modifier & description |
---|---|
1 | It appends to string. |
2 | It appends to string. |
3 | It appends a character to string. |
4 | It is used to assign the content to string. |
5 | It is used to inset the value to string. |
6 | It is used to erase characters from string. |
7 | It is used to replace portion of string. |
8 | It is used to swap string values. |
9 | It is used to delete last character. |
String operations
Sr.No. | String operation & description |
---|---|
1 | It is used to get C string equivalent. |
2 | It is used to get string data. |
3 | It is used to get an allocator. |
4 | It is used to copy sequence of characters from string. |
5 | It is used to find content in string. |
6 | It is used to find last occurrence of content in string. |
7 | It is used to find character in string. |
8 | It is used to find character in string from the end. |
9 | It is used to find absence of character in string. |
10 | It is used to find non-matching character in string from the end. |
11 | It is used to generate substring. |
12 | It is used to compare strings. |