htmlパース 実験

単語を解析したかったので、組んでみた.

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

int main() {
  cout << "ファイル名入力(拡張子込み)で入力してください." << endl;
  string filename;
  cin >> filename;
  ifstream ifs(filename.c_str());
  string str;
  ofstream ofs("t.txt");
  int cnt = 6000;
  string prev = "aaaaaa";
  while(getline(ifs, str)) {
    char word[60], flag[10];
    sscanf(str.c_str(), "var see_ok_%s = %s", word, flag);
    if(flag[0] == 'f') {
      ofs << word << " ";
    }
    string wordstr(word);
    if(word[0] >= 'a' && word[0] <= 'z' && word == prev) {
      cout << cnt << endl; break;
    } else {
      prev = wordstr;
    }
    if(--cnt < 0) break;
  }
  ofs << endl;
}