Substring Searching & String Manipulation

🟡 Intermediate

📖 Definition

std::string provides .find() to locate substring index offsets (returning std::string::npos on failure), .substr(pos, count) to slice substrings, and .replace() to overwrite characters.

💡 Code Example

#include <iostream>
#include <string>

int main() {
    std::string text = "ISO C++17 Standard";
    size_t pos = text.find("C++17");

    if (pos != std::string::npos) {
        std::cout << "Found C++17 at index " << pos << "\n";
        std::string sub = text.substr(pos, 5);
        std::cout << "Extracted: " << sub << "\n";
    }
    return 0;
}