#include#include int main(int argc, char** argv) { std::string str = "Hello World!"; int pos = str.find_first_of("aeiou"); if (pos != std::string::npos) { std::cout << "Vowel found at position " << pos << std::endl; } else { std::cout << "No vowel found in the string." << std::endl; } return 0; }
#includeIn this example, we find the position of the first occurrence of any letter in the given string "C++ Programming Language". If a letter is found, its value is printed, otherwise a message stating that no letter was found is printed. The std::string::find_first_of function is a part of the C++ Standard Library.#include int main(int argc, char** argv) { std::string str = "C++ Programming Language"; int pos = str.find_first_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); if (pos != std::string::npos) { std::cout << "The first letter in the string is " << str[pos] << std::endl; } else { std::cout << "No letter found in the string." << std::endl; } return 0; }