您的位置:首页 > Web前端 > HTML

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

2015-03-28 14:16 357 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: