find if substring is in string c++ code example
Example 1: c++ check if string contains substring
string str ("There are two needles in this haystack.");
string str2 ("needle");
if (str.find(str2) != string::npos) {
}
Example 2: check if character in string c++
std::string s = "hell[o";
if (s.find('[') != std::string::npos)
;
else
;
Example 3: find substring in string c++
std::string parentstring = "Hello Agnosticdev, I love Tutorials";
std::string substring = "Agnosticdev";
auto index = parentstring.find(substring);