ProgramsC++

String Operations Programs

C++ string operation programs: copy, join, reverse, check palindromes, remove vowels, characters, or spaces, count letters, and read ASCII codes, with several methods each.

10 programs · open one, then the next

Start with Copy Strings
  1. 01Copy StringsBeginnerCopy a string in C++ four ways: assignment, the copy constructor, assign(), and strcpy for char arrays. See why string copies are safe and strcpy can overflow.Open example →
  2. 02Concatenate Two StringsBeginnerJoin strings in C++ with +, +=, append(), and strcat for C-style arrays. Learn which methods build a new string, which modify in place, and the strcat trap.Open example →
  3. 03Reverse a StringBeginnerReverse a string in C++ with std::reverse, a two-pointer swap loop, and reverse iterators. Traces how the indexes meet in the middle and why it stops at half.Open example →
  4. 04Reverse a SentenceIntermediateReverse the order of words in a sentence in C++: split with stringstream, then rebuild with a vector, a stack, recursion, or an in-place two-pointer pass.Open example →
  5. 05Check PalindromeIntermediateCheck whether a string is a palindrome in C++ by comparing characters from both ends. Covers case with tolower, skipping non-letters, and a reversed copy.Open example →
  6. 06Find ASCII ValueBeginnerPrint the ASCII code of a character in C++ three ways: a C-style cast, static_cast, and implicit conversion to int. Compares them and lists key codes.Open example →
  7. 07Remove VowelsIntermediateRemove all vowels from a string in C++ with a loop that builds a new string, erase with remove_if, and a find-based check. Covers the erase-remove idiom.Open example →
  8. 08Count Vowels and ConsonantsIntermediateCount vowels, consonants, digits, and other characters in a C++ string with isalpha and tolower. Shows why spaces and punctuation are not consonants.Open example →
  9. 09Remove CharactersIntermediateRemove chosen characters from a string in C++ with erase, remove_if, a set, two pointers, or a new string. Explains the erase-remove idiom and its costs.Open example →
  10. 10Remove SpacesIntermediateRemove spaces and other whitespace from a C++ string six ways, including erase-remove, isspace, stringstream, and an in-place two-pointer loop.Open example →