std::find_first_of 

Searches in the set of elements for the first occurrence of any element of another set, and

 std::find 

Finds in the same range the first element that satisfies certain conditions. It is clear how these search algorithms differ.

But what is the difference between std::string::find and std::string::find_first_of ? If it is not difficult to give an example, where one function is preferable to another.

    1 answer 1

    Talking about the preference of completely different functions is somehow strange. Where it is preferable, for example, to search for the square root, and where is the logarithm? :)

    find searches for a substring, and find_first_of any character in the passed string.

    Roughly speaking, for the string "abracadabra" and the substring "cad" find returns 4, and find_first_of 0 (the first letter a is in "cad" ).