The Program in C++ Program to Count Number of unique characters of two given strings is given below:
#include <iostream>
#include <string>
#include <set>
using namespace std;
int countUniqueCharacters(string str1, string str2)
{
set<char> s;
for (char c : str1) {
s.insert(c);
}
for (char c : str2) {
s.insert(c);
}
return s.size();
}
int main()
{
string str1, str2;
cout << "Hello Codeauri Family,Enter the first string here : ";
getline(cin, str1);
cout << "Hello Codeauri Family,Enter the Second string here: ";
getline(cin, str2);
cout << "Well, the Number of unique characters are: " << countUniqueCharacters(str1, str2) << endl;
return 0;
}
Output:
Hello Codeauri Family,Enter the first string here : possibility
Hello Codeauri Family,Enter the Second string here: chances
Well, the Number of unique characters are: 13
Pro-Tips💡
This program uses the countUniqueCharacters
function to count the number of unique characters of two given strings str1
and str2
.
The function uses a set
to store the unique characters and a loop to insert each character from both strings into the set
.
The size of the set
is then returned as the result.
The main
function takes two input strings from the user and calls the countUniqueCharacters
function to get the number of unique characters, then outputs the re
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.