본문 바로가기

C++

[C++ 예제] C++ 텍스트 파일 파싱하기

네이버 메인에서 가져온 html파일을 test.txt로 저장하였다.

네이버 검색순위가 공통적으로 갖고있는 문자열을 통해 원하는 문자열을 찾는 프로그램 예제이다.
find함수를 통해 구현했다.
 



 

#include <iostream>

#include <string>
#include <cstring>>
#include <fstream>

using namespace std;




int main()

{

	// 파일 읽기 준비

	ifstream in("test.txt");

	string s="A"; 


	while(s!="</body> </html>")
	{
		getline(in, s);
		if(!s.find("<span class=\"ah_k\""))	//0은 거짓 0이 아니면 참 
		{
			cout<<s<<endl;
		}
		
		
	}

	return 0;

}