《C++ PRIMER》中的例子,但也许由于名字空间造成编译无法通过,请帮忙修改
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <fstream.h>
#include <iostream.h>
#include <stddef.h>
#include <ctype.h>
using std::string;
using std::vector;
using std::pair;
using std::map;
typedef pair <short,short> location;
typedef vector <location> loc;
typedef vector <string> textex;
typedef pair <textex*,loc*> text_loc;
class textquery
{
public:
textquery()
{
memset(this,0,sizeof(textquery));
}
static void filter_elements(string felems)
{
filt_elems=felems;
}
void query_text();
void display_map_text();
void display_text_locations();
void doit()
{
retrieve_text();
separate_words();
filter_text();
suffix_text();
strip_caps();
build_word_map();
}
private:
void retrieve_text();
void separate_words();
void filter_text();
void strip_caps();
void suffix_text();
void suffix_s(string&);
void build_word_map();
vector<string> *lines_of_text;
text_loc *text_locations;
map<string,loc*> *word_map;
static string filt_elems;
};
string textquery::filt_elems("\",.;:!?)(\\/");
void main()
{
textquery tq;
tq.doit();
tq.query_text();
tq.display_map_text();
}
void textquery::retrieve_text()
{
string file_name;
cout<<"please enter file name: ";
cin>>file_name;
ifstream infile(file_name.c_str(),ios::in);
if(!infile)
{
cerr<<"oops!unable to open file"
<<file_name.c_str()<<"--bailing out!\n";
exit(-1);
}
else cout<<"\n";
lines_of_text=new vector<string>;
string textline;
while(getline(infile,textline,'\n'))
{
lines_of_text->push_back(textline);
}
infile.close();
}