例如:
<html>
<head>
<title> Test </title>
</head><body>
<font = 5><b>Hello World!</b></font>
</body>
</html>只保留
Test 和
Hello World!
<html>
<head>
<title> Test </title>
</head><body>
<font = 5><b>Hello World!</b></font>
</body>
</html>只保留
Test 和
Hello World!
然后打开Txt文件,写入其中,再关闭文件。
#include <iostream>
#include <fstream>
#include <string>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
string strin,strout;
cout<<"Enter the html(input) file: ";
cin>>strin;
cout<<"\nEnter the txt(output) file: ";
cin>>strout;
ifstream filein(strin.c_str());
if ( !filein )
{
cerr << "file could not be opened!";
exit( 1 );
}
ofstream fileout(strout.c_str());
if ( !fileout)
{
cerr << "file could not be opened!";
exit( 1 );
}
bool check;
list<char> charline;
char ch;
filein.seekg( 0 );
while ( filein.get( ch ) )
{
if(ch=='<')
{
check=false;
continue;
}
if(check)
charline.push_back(ch);
if(ch=='>')
check=true;
}
copy(charline.begin(),charline.end(),ostream_iterator<char>(fileout));
return 0;
}
但也大致看懂了你的代码!
对于一般情况,你的做法能得到正确的结果但对于一般意义的"<"和">"却不能正确区分
in.txt
1<2out.txt
1
http://www.hackhome.com/2004/9-8/19133.html