#include#include using namespace std; int main() { string str = "Hello, World!"; int index = str.find_first_not_of("Hloe, Wrd!"); //Returns index of the first character not in the set of specified characters cout << "Index of first character not in the set: " << index << endl; return 0; }
#includeIn the above example, the string function find_first_not_of() is used to find the index of the first character in the string that does not match any of the characters specified in the argument, which is "string" and the index is 8. If all the characters in the string are present in the specified set, the function returns string::npos (which represents the end of the string). The string find_first_not_of() function is part of the C++ Standard Library.#include using namespace std; int main() { string str = "This is a string"; int index = str.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "); //Returns index of the first character not in the set of specified characters if (index == string::npos) //If all characters are present in the set cout << "All characters present in the set" << endl; else cout << "Index of first character not in the set: " << index << endl; return 0; }