[c++] 특정 문자열 읽기
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::ifstream file("example.txt");
std::string line;
if (file.is_open()) {
while (std::getline(file, line)) {
if (line.find("특정문자열") != std::string::npos) {
std::cout << "찾은 문자열: " << line << std::endl;
}
}
file.close();
} else {
std::cout << "파일을 열 수 없습니다." << std::endl;
}
return 0;
}
이 코드는 “example.txt” 파일을 열고 각 줄을 읽어서 “특정문자열”이 포함된 줄을 찾아 출력합니다. 필요에 따라 파일 경로나 찾고자 하는 문자열을 수정해야 합니다.