Strings In Depth8 / 15
Up next

find

#include <print>
#include <string>

int main() {
    std::string s = "hello world";
    auto pos = s.find("world");
    // find returns std::string::npos when there is no match
    if (pos != std::string::npos) {
        std::println("found at {}", pos);
    }
}
What you're solving

locate a substring or npos