C++ STL string
C++ examples for STL:string
HOME
C++
STL
string
Description
Click the following links for the tutorial for STL and string.
Decrementing string::iterator
Using string Iterators to Alter Data
String reverse_iterator with rbegin() and rend(), const Iterators
Move backward through a string from end to beginning via string::reverse_iterator
Search for a single character in a string using find_first_of.
Searching Within Strings using string::find Method
Using auto with Standard for Loops on string value
Using auto in Range-Based for Loops on string value
Range-Based for with Constant Access on string value
Range-Based for loop on string value
Looping over a String
Formatting Data with stringstream
Building Strings with the standard string Class
Read number from user
Fibonacci: A 64-Bit Example
Create a string that is the sum of two strings
Insert a phrase at insertion point
Remove any spaces within a string
Processing Strings to remove spaces
Defines a generic function that trims trailing whitespace.
Uses a function template to trim characters from the end of any kind of character string.
Trimming a String, use iterators to identify the portion of the string, and use the erase member function to remove it.
Padding a String, fill a string with a number of occurrences of some character to a certain width.
Split a delimited string into multiple strings.
Copy the string to another string, but backward, use reverse iterators
To reverse a string "in place" without using a temporary string, use the reverse function template in the <algorithm> header:
Getting the Length of a String, String length and capacity
Doing a Case-Insensitive String Search
Doing a Case-Insensitive String Comparison
Converting a String to Lower- or Uppercase
Remove all substrings from a string with template
Removing a Substring from a String
Create template to find the nth Instance of a Substring
Finding the nth Instance of a Substring
Counts the number of unique characters in a string.
Finding Things in Strings, search a string for something.
Joining C-style strings with template
Joining a Sequence of Strings, join them together into a single, long string.
Tokenizing a String, break a string into pieces using a set of delimiters.
Use string subscript out of range with string member function "at"
Use string overloaded subscript operator to create lvalue
Use overloaded assignment (=) operator with self-assignment
Use string copy constructor
Use substr "to-end-of-string" option
Use string member function substr
Use overloaded string concatenation operator with a char * string
Use overloaded string concatenation operator
Use string member-function empty
Using an iterator to output a string.
Conversion to C-Style Pointer-Based char* Strings
Inserting Characters into a string
Replacing Characters in a string, erase and replace
Finding Substrings and Characters in a string
String size and capacity.
Swapping strings
Get Substrings
Comparing strings
Demonstration string assignment and concatenation.
Reversing a string with Iterators
Replace punctuation marks with spaces and uses C-string function strtok to tokenize string into individual words.
Remove Characters from a string
Inserts the characters "******" in the exact middle of a string.
Counts the total number of vowels in a sentence. Output the frequency of each vowel.
Read a sentence and counts the number of palindromes in it.
Each letter in string is replaced with another letter.
Printing a string Backward, convert case
Read first name and last name and concatenates the two into a new string.
Reads in several strings and prints only those ending in "r" or "ay".
Using iterators that demonstrates the use of functions rbegin and rend.
String Encryption with character rotation
Input from an istringstream
Using an ostringstream object.
Replacing a word in text by asterisks.
Reversing the order of a string of characters.
Reading and validating a date of birth.
Finding words that begin with a given letter.
Check for anagrams.
Replacing words in a string
Searching a string for characters from a set
Searching a string for a substring
Reads any number of names and sorts them into ascending sequence:
Accessing characters in a string
Concatenating strings
Use for loop to access each character in string one by one and use position index
Count letter and digit inside a string
Search sub string with find function and get sub string with substr function
Insert, replace and append characters to string
Access a char from string one by one with at() function
Check string length and compare string values
The string and char Data Types
Read a line of text into string with getline function
Create string object is various ways
Input a string via cin.
Set the capacity of str4 to 128.
Use push_back() to add characters to a string.
Erase string content
Create a string object using another string object.
Compare two strings.
Obtain a substring.
Insert one string into another.
Concatenate two strings with plus operator
Assign one string to another
Display the characters in a string one at a time by using the indexing operator.
Display the capacity of a string
Display the size of a string
Display the maximum string length.
Output a string via cout
Using the string literal as an argument to create string objects
Searching for the last occurrence of any character other than o, n, e, or space
Searching for the first occurrence of any character other than o, n, e, or space
Searching for the last occurrence of t or h
Searching for the first occurrence of t or h
Searching for the last occurrence of a sub string
Searching for the first occurrence of
Use a reverse iterator to display the string in reverse
Use an iterator to cycle through the characters of a string.
Implement search-and-replace for string objects.
Create a class called tokenizer that tokenizes a string.
Erase a string with iterator
Replace a sub string with another sub string using iterator
Insert into string by using the iterator version of insert()
Use STL find() algorithm to obtain an iterator to the start of the first 'a'
Use an iterator with the STL transform() algorithm to convert a string to uppercase.
Implement case-insensitive search and search-and-replace for string objects.
Create a string from a vector<char>.
Implement operator-( ) and operator-=( ) for objects of type string:
Convert a string object into a null-terminated string.