Answer the question
In order to leave comments, you need to log in
How to compare two elements of type string?
I have two elements of type string
Whether it is necessary to check identical words are written. If so, output that character
. For example,
string firstVar = "example";
string secondVar = "example";
And now, if these variables have the same words, then display firstVar, otherwise, display
secondVar
Answer the question
In order to leave comments, you need to log in
ummm, operator == will suit?
if (firstElem == secondElem)
{
...
}
You can use just ==, you can use the strcmp function (it's intended for const char*, so it's more versatile for large projects). The string class has a c_str() function that returns a string as a const char*.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question