过滤网页中的HTML标签C++代码

来源:互联网 发布:利用单片机制作恒流源 编辑:程序博客网 时间:2024/06/05 16:42
#include<iostream>#include<fstream>#include<string>#include<stdlib.h>using namespace std;int Filter(string infile,string outfile){char character;bool text_state(true);//string infile,outfile;ifstream html;ofstream htmltext;//cout<<"The name of input file"<<endl;//cin>>infile;//cout<<"The name of output file"<<endl;//cin>>outfile;html.open(infile.c_str());if(html.fail()){               cerr<<"Error opening input file\n";               exit(1);               }htmltext.open(outfile.c_str());html.get(character);while(!html.eof()){                  if(text_state)                  {                                if(character=='<')                                text_state=false;                                else                                htmltext<<character;                                }                  else                  {                      if(character=='>')                      text_state=true;                      }                      html.get(character);                  }html.close();htmltext.close();return 0;    } int main(){    string infile,outfile;    cout<<"The name of input file"<<endl;    cin>>infile;    cout<<"The name of output file"<<endl;    cin>>outfile;    Filter(infile,outfile);    system("pause");    return 0;    }

0 0
原创粉丝点击