Hi, im wondering if there is a way to compare two strings that aren't identical with each other.
instance:
1 2 3 4 5 6 7
|
str1="ABC123";
str2="A****3";
if(str1==str2)
{
cout << "It's a match";
}
|
Last edited on
Yes, with a semicolon after str2 (line 2).
1 2 3 4 5 6 7
|
string str1="ABC123";
string str2="A****3";
if(str1==str2)
{
cout << "It's a match";
}
|
Last edited on
Sorry forgot that. However my question is not "can i check if two strings are the same" but if some parts of the two strings are the same.
For instance if some letters in one string is == to some letters in another string.
eg, search an array for names starting with m and ending with e:
mike == m**e;
Does that make sense?
1 2 3 4 5 6 7 8 9
|
string str1="ABC123";
string str2="A****3";
for(char w1 : str1)
for(char w2 : str2)
{
if(w1 == w2)
std::cout << w1 << " is present in both strings\n";
continue;
}
|
A is present in both strings
3 is present in both strings |
Last edited on
My command line for building a code is:
g++ -Wall -Wextra -std=c++11 -pedantic -o qaz qaz.cpp
Note that the program is built according to C++11 standard.
It's a match with your problem?