D
D
Danil Fliginskiy2020-05-11 14:31:18
C++ / C#
Danil Fliginskiy, 2020-05-11 14:31:18

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

2 answer(s)
1
15432, 2020-05-11
@danilfliginskiy

ummm, operator == will suit?

if (firstElem == secondElem)
{
...
}

S
StillDontKnowMyName, 2020-05-12
@StillDontKnowMyName

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 question

Ask a Question

731 491 924 answers to any question