I have a variable of type std::string
. I want to check if it contains a certain std::string
. How would I do that?
Is there a function that returns true if the string is found, and false if it isn't?
cstringsubstring
I have a variable of type std::string
. I want to check if it contains a certain std::string
. How would I do that?
Is there a function that returns true if the string is found, and false if it isn't?
Best Answer
Use
std::string::find
as follows:Note: "found!" will be printed if
s2
is a substring ofs1
, boths1
ands2
are of typestd::string
.