[c++] 문자열에서 특정 패턴 이후의 부분 추출하는 방법

예를 들어, 다음과 같이 특정 패턴(“pattern”) 이후의 부분을 추출하려고 합니다:

#include <iostream>
#include <string>

int main() {
    std::string originalString = "This is the original pattern example string";
    std::string pattern = "pattern";

    size_t found = originalString.find(pattern);
    if (found != std::string::npos) {
        std::string extractedString = originalString.substr(found + pattern.length());
        std::cout << "Extracted: " << extractedString << std::endl;
    } else {
        std::cout << "Pattern not found" << std::endl;
    }

    return 0;
}

이 예제는 문자열에서 “pattern” 이후의 부분을 추출하여 출력합니다. “pattern not found”가 출력되면 “pattern”이 문자열에 존재하지 않음을 의미합니다.