본문 바로가기
프로그래밍 _공부자료./C++ 공부

문자열 은 똑같은데 하나의 숫자만 가변일때 해결법 c++

by 대구부자 2023. 11. 1.
반응형

#include <iostream>
#include <string>
#include <regex>

int main() {
    std::string logMessage = "데이터 오류 때문에 0 행이(가) 로드되지 않았습니다.";

    std::regex errorMessageRegex("데이터 오류 때문에 (\\d+) 행이\\(가\\) 로드되지 않았습니다."); // 오류 메시지에 매칭되는 정규 표현식
    std::smatch match;

    if (std::regex_search(logMessage, match, errorMessageRegex)) {
        std::string numberString = match[1].str(); // 추출된 숫자를 문자열로 저장
        int number = std::stoi(numberString); // 문자열을 정수로 변환

        std::cout << "로드되지 않은 행의 수: " << number << std::endl;
    }

    return 0;
}

반응형

댓글