C++ STL string

C++ examples for STL:string

Description

Click the following links for the tutorial for STL and string.

  1. Decrementing string::iterator
  2. Using string Iterators to Alter Data
  3. String reverse_iterator with rbegin() and rend(), const Iterators
  4. Move backward through a string from end to beginning via string::reverse_iterator
  5. Search for a single character in a string using find_first_of.
  6. Searching Within Strings using string::find Method
  7. Using auto with Standard for Loops on string value
  8. Using auto in Range-Based for Loops on string value


  9. Range-Based for with Constant Access on string value
  10. Range-Based for loop on string value
  11. Looping over a String
  12. Formatting Data with stringstream
  13. Building Strings with the standard string Class
  14. Read number from user
  15. Fibonacci: A 64-Bit Example
  16. Create a string that is the sum of two strings


  17. Insert a phrase at insertion point
  18. Remove any spaces within a string
  19. Processing Strings to remove spaces
  20. Defines a generic function that trims trailing whitespace.
  21. Uses a function template to trim characters from the end of any kind of character string.
  22. Trimming a String, use iterators to identify the portion of the string, and use the erase member function to remove it.
  23. Padding a String, fill a string with a number of occurrences of some character to a certain width.
  24. Split a delimited string into multiple strings.
  25. Copy the string to another string, but backward, use reverse iterators
  26. To reverse a string "in place" without using a temporary string, use the reverse function template in the <algorithm> header:
  27. Getting the Length of a String, String length and capacity
  28. Doing a Case-Insensitive String Search
  29. Doing a Case-Insensitive String Comparison
  30. Converting a String to Lower- or Uppercase
  31. Remove all substrings from a string with template
  32. Removing a Substring from a String
  33. Create template to find the nth Instance of a Substring
  34. Finding the nth Instance of a Substring
  35. Counts the number of unique characters in a string.
  36. Finding Things in Strings, search a string for something.
  37. Joining C-style strings with template
  38. Joining a Sequence of Strings, join them together into a single, long string.
  39. Tokenizing a String, break a string into pieces using a set of delimiters.
  40. Use string subscript out of range with string member function "at"
  41. Use string overloaded subscript operator to create lvalue
  42. Use overloaded assignment (=) operator with self-assignment
  43. Use string copy constructor
  44. Use substr "to-end-of-string" option
  45. Use string member function substr
  46. Use overloaded string concatenation operator with a char * string
  47. Use overloaded string concatenation operator
  48. Use string member-function empty
  49. Using an iterator to output a string.
  50. Conversion to C-Style Pointer-Based char* Strings
  51. Inserting Characters into a string
  52. Replacing Characters in a string, erase and replace
  53. Finding Substrings and Characters in a string
  54. String size and capacity.
  55. Swapping strings
  56. Get Substrings
  57. Comparing strings
  58. Demonstration string assignment and concatenation.
  59. Reversing a string with Iterators
  60. Replace punctuation marks with spaces and uses C-string function strtok to tokenize string into individual words.
  61. Remove Characters from a string
  62. Inserts the characters "******" in the exact middle of a string.
  63. Counts the total number of vowels in a sentence. Output the frequency of each vowel.
  64. Read a sentence and counts the number of palindromes in it.
  65. Each letter in string is replaced with another letter.
  66. Printing a string Backward, convert case
  67. Read first name and last name and concatenates the two into a new string.
  68. Reads in several strings and prints only those ending in "r" or "ay".
  69. Using iterators that demonstrates the use of functions rbegin and rend.
  70. String Encryption with character rotation
  71. Input from an istringstream
  72. Using an ostringstream object.
  73. Replacing a word in text by asterisks.
  74. Reversing the order of a string of characters.
  75. Reading and validating a date of birth.
  76. Finding words that begin with a given letter.
  77. Check for anagrams.
  78. Replacing words in a string
  79. Searching a string for characters from a set
  80. Searching a string for a substring
  81. Reads any number of names and sorts them into ascending sequence:
  82. Accessing characters in a string
  83. Concatenating strings
  84. Use for loop to access each character in string one by one and use position index
  85. Count letter and digit inside a string
  86. Search sub string with find function and get sub string with substr function
  87. Insert, replace and append characters to string
  88. Access a char from string one by one with at() function
  89. Check string length and compare string values
  90. The string and char Data Types
  91. Read a line of text into string with getline function
  92. Create string object is various ways
  93. Input a string via cin.
  94. Set the capacity of str4 to 128.
  95. Use push_back() to add characters to a string.
  96. Erase string content
  97. Create a string object using another string object.
  98. Compare two strings.
  99. Obtain a substring.
  100. Insert one string into another.
  101. Concatenate two strings with plus operator
  102. Assign one string to another
  103. Display the characters in a string one at a time by using the indexing operator.
  104. Display the capacity of a string
  105. Display the size of a string
  106. Display the maximum string length.
  107. Output a string via cout
  108. Using the string literal as an argument to create string objects
  109. Searching for the last occurrence of any character other than o, n, e, or space
  110. Searching for the first occurrence of any character other than o, n, e, or space
  111. Searching for the last occurrence of t or h
  112. Searching for the first occurrence of t or h
  113. Searching for the last occurrence of a sub string
  114. Searching for the first occurrence of
  115. Use a reverse iterator to display the string in reverse
  116. Use an iterator to cycle through the characters of a string.
  117. Implement search-and-replace for string objects.
  118. Create a class called tokenizer that tokenizes a string.
  119. Erase a string with iterator
  120. Replace a sub string with another sub string using iterator
  121. Insert into string by using the iterator version of insert()
  122. Use STL find() algorithm to obtain an iterator to the start of the first 'a'
  123. Use an iterator with the STL transform() algorithm to convert a string to uppercase.
  124. Implement case-insensitive search and search-and-replace for string objects.
  125. Create a string from a vector<char>.
  126. Implement operator-( ) and operator-=( ) for objects of type string:
  127. Convert a string object into a null-terminated string.