bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/C++/C++ Reference
C++•C++ Reference

C++ string Library

C++ string Functions

The <string> library has many functions that allow you to perform tasks on strings.

A list of all string functions can be found in the table below.

FunctionDescription
append()Adds characters or another string to the end of the current string
at()Returns the character at a specified index, with bounds checking
back()Accesses the last character in the string
begin()Returns an iterator pointing to the first character of the string
c_str()Returns a C-style null-terminated string
clear()Removes all characters, making the string empty
compare()Compares the string with another string and returns the result
copy()Copies characters from the string into a character array
data()Returns a pointer to the string's internal character array
empty()Checks whether the string is empty
end()Returns an iterator pointing just past the last character
erase()Deletes part of the string by position and length
find()Finds the first occurrence of a character or substring
front()Accesses the first character in the string
insert()Inserts characters or a substring at a specified position
length()Returns the number of characters in the string
max_size()Returns the maximum number of characters of a string
operator[]Returns the character at a given index
pop_back()Removes the last character from the string
push_back()Adds a single character to the end of the string
replace()Replaces part of the string with new content
rfind()Finds the last occurrence of a character or substring
resize()Changes the size of the string, either trimming or padding it
size()Alias of length() ; returns the string's length
substr()Returns a portion of the string, starting at a given index and length
swap()Exchanges the contents of two strings

Learn more about strings in our C++ Strings Tutorial .

Previous

C++ cmath Library

Next

C++ cstring Library