example3_string_searching.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

int main() {
    std::string str = "The quick brown fox jumps over the lazy dog";
    
    // Find substring
    size_t pos = str.find("fox");
    if (pos != std::string::npos) {
        std::cout << "Found 'fox' at position: " << pos << std::endl;
    }
    
    // Find character
    pos = str.find_first_of("aeiou");
    if (pos != std::string::npos) {
        std::cout << "First vowel at position: " << pos << std::endl;
    }
    
    return 0;
}
Back to string