how to check whether a character is present in a string in 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: check if char in string c++
std::string s = "hell[o";
if (s.find('[') != std::string::npos)
; // found
else
; //
Example 3: find in string c++
size_t find (const string& str, size_t pos = 0) const;