最后用c++实现了一把,因为stl中尚未包含regular expression,因此我使用了boost中的regex++。不过因为不是很熟悉,所以代码很蹩脚,将就看了。呵呵。
#include <string>
#include <boost/regex.hpp>
#include <iostream>
#include <fstream>
using namespace std;
void readfile( const char* filename, string& str );
void writefile( const char* filename, const string str );
void filter( const string input, string& output );
int main(int argc, const char* argv[])
{
if( argc < 3 )
{
cout<< "please enter 2 filenames(e.g. in.txt out.txt)" << endl;
return 1;
}
string strin, strout;
readfile( argv[1], strin );
filter( strin, strout );
writefile( argv[2], strout );
}
void readfile( const char* filename, string& str )
{
ifstream in( filename );
str.erase();
str.reserve( in.rdbuf()->in_avail() );
string strtemp;
while( !in.eof() )
{
in >> strtemp;
str.append(strtemp);
}
in.close();
}