In C++, a string is an object of std::string class that represents a sequence of characters. On strings, we can perform operations like concatenation, comparison, and conversion. The String class stores character as a sequence of bytes and allow single-byte characters to be accessed. There are two types of string representations in C++: C-style character strings and the String class. C-style string literals are like a one-dimensional character array containing a string and are null-terminated.
The following section contains various C++ programs on strings, string operations, string functions, palindrome programs, string matching, and encryption algorithms. Each sample program includes a program description, C++ code, and program output. All examples have been compiled and tested on Windows and Linux systems.
Here is the listing of C++ programming examples on Strings:
- C++ Programs on String Operations
- C++ Programs on String Functions
- C++ Programs on Strings
- C++ Programs on String Matching
- C++ Programs on Cryptography
- C++ Programs on Longest Common SubString/SubSequence
1. C++ Programs on String Operations
Program | Description |
---|---|
String Concatenation in C++ | C++ Program to Concatenate Two Strings |
Compare Two Strings in C++ | C++ Program to Compare Two Strings |
Remove Character from String in C++ | C++ Program to Remove Specific Character from the String |
Remove Spaces from String in C++ | C++ Program to Remove Spaces from a String |
Replace all Spaces with % in String in C++ | C++ Program to Replace All Spaces in a String with % |
Reverse Each Word in a String in C++ | C++ Program to Reverse Each Word in a String |
Change Case of Character in String in C++ | C++ Program to Convert Given Characters of a String to Opposite Case |
2. C++ Programs on String Functions
Program | Description |
---|---|
strncmp() Function in C++ | C++ Program to Implement strncmp() Function |
strpbrk() Function in C++ | C++ Program to Implement strpbrk() Function |
strncpy() Function in C++ | C++ Program to Implement strncpy() Function |
strchr() Function in C++ | C++ Program to Implement strchr() Function |
strspn() Function in C++ | C++ Program to Implement strspn() Function |
3. C++ Programs on Strings
Program | Description |
---|---|
String Length Program in C++ | C++ Program to Find the Length of a String |
Count Number of Words from a String in C++ | C++ Program to Count Number of Words in a String |
Count Vowels, Consonants and Special Characters from a String in C++ | C++ Program to Count the Number of Vowels/Consonants/Numbers/Special Characters in a String |
Permutation of a String in C++ | C++ Program to Print All Permutations of a Given String |
Sum of ASCII Value of a String in C++ | C++ Program to Find the Sum of ASCII Value of All Characters in the String |
Find Frequency of Characters in a String in C++ | C++ Program to Find Frequency and Position of Characters in a String |
String Class in C++ | C++ Program to Demonstrate the use of String Class |
Toggle Cases in a String in C++ | C++ Program to Toggle Cases in a String |
String Palindrome Program in C++ | C++ Program to Check if a String is Palindrome |
Anagram Program in C++ | C++ Program to Check whether two Strings are Anagrams |
Grep, Egrep and Fgrep in C++ | C++ Program to Implement Grep, Egrep and Fgrep Commands |
Permutations using BackTracking in C++ | C++ Program to Print All Permutations using BackTracking |
Palindrome Partitioning Problem in C++ | C++ Program to Solve Palindrome Partitioning Problem |
4. C++ Programs on String Matching
Program | Description |
---|---|
Naive String Matching in C++ | C++ Program to Perform Naive String Matching |
Knuth Morris Pratt Algorithm in C++ | C++ Program to Implement Knuth-Morris-Pratt Algorithm for Pattern Searching |
Boyer Moore Algorithm in C++ | C++ Program to Implement Boyer-Moore Algorithm for Pattern Searching |
Aho-Corasick Algorithm in C++ | C++ Program to Implement Aho-Corasick Algorithm for Pattern Searching |
Rabin Karp String Matching Algorithm in C++ | C++ Program to Implement Rabin-Karp Method for Pattern Searching |
String Matching using Bitap Algorithm in C++ | C++ Program to Implement Bitap Algorithm for String Matching |
Online String Matching using Wagner and Fisher in C++ | C++ Program to Implement Wagner and Fischer Algorithm for Online String Matching |
Levenshtein Distance Computing Algorithm in C++ | C++ Program to Implement Levenshtein Distance Computing Algorithm |
String Matching Using Library in C++ | C++ Program to Perform String Matching Using String Library |
String Matching Using Vectors in C++ | C++ Program to Implement String Matching Using Vectors |
String Search Algorithm in C++ | C++ Program to Implement String Search Algorithm for Short Text Sizes |
Repeated Search Pattern in C++ | C++ Program to Repeatedly Search the Same Text |
5. C++ Programs on Cryptography
Program | Description |
---|---|
Monoalphabetic Cypher in C++ | C++ Program to Implement the Monoalphabetic Cipher |
Caesar Cypher in C++ | C++ Program to Implement Caesar Cipher |
Vigenere Cypher in C++ | C++ Program to Implement the Vigenere Cipher |
Hill Cypher in C++ | C++ Program to Implement the Hill Cipher |
Affine Cipher in C++ | C++ Program to Implement Affine Cipher |
Playfair Cipher Encryption Program in C++ | C++ Program to Encrypt Message using Playfair Cipher |
Playfair Cipher Decryption Program in C++ | C++ Program to Decrypt Message using Playfair Cipher |
One Time Pad Algorithm in C++ | C++ Program to Implement the One Time Pad Algorithm |
RSA Algorithm in C++ | C++ Program to Implement the RSA Algorithm |
Transposition Technique Program in C++ | C++ Program to Perform Cryptography using Transposition Technique |
6. C++ Programs on Longest Common SubString/SubSequence
Program | Description |
---|---|
Longest Common Substring in C++ | C++ Program to Find Length of Longest Common Substring |
Longest Increasing Subsequence in C++ | C++ Program to Find the Longest Increasing Subsequence |
Longest Prefix Match Algorithm in C++ | C++ Program to Implement Longest Prefix Matching |