find chars in string c++ code example
Example 1: how to check string contains char in c++
std::string s = "Hello";
if (s.find('e') != std::string::npos)
cout << "Found";
else
cout << "Not Found";
Example 2: find character in string c++
auto char_to_find = 'a'
if (str.find(char_to_find) != std::string::npos) {
// character found
}
Example 3: string .find in c++
std::string t = "Banana Republic";
std::string s = "nana";
std::string::size_type i = t.find(s);
if (i != std::string::npos)
t.erase(i, s.length());