[Dev-C++] problem with iterating vector<string,allocator<string> > in vc++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: bhadram r. <bha...@ya...> - 2005-09-17 14:24:41
|
dear friends,
The following code is giving error like it cannot find the << convertor for vector<string,allocator<string> > object how to solve this problem. Please help me.
Thanking you,
yours sincerely,
bhadram
# pragma warning(disable:4786)
# include <textquery2.h>
using namespace bhadram2;
int main()
{
TextQuery* tq=new TextQuery;
tq->retrieve_text();
tq->strip_lines();
tq->display_word_locations();
return 0;
}
# include <iostream>
# include <fstream>
# include <string>
# include <algorithm>
# include <vector>
# include <set>
# include <map>
using namespace std;
namespace bhadram2
{
typedef vector<string,allocator<string> > vecString;
typedef pair<short,short> Location;
typedef vector<Location,allocator<Location> > Locations;
typedef pair<vecString*,Locations*> WordLocations;
class TextQuery
{
private:
vector<string>* lines_of_text;
WordLocations* wordLocations;
public:
retrieve_text();
display_lines_of_text();
strip_lines();
display_word_locations();
};
TextQuery::display_word_locations()
{
vector<string,allocator<string> >* words=wordLocations->first;
Locations* locations=wordLocations->second;
vector<string,allocator<string> >::iterator iter=words->begin();
while(iter!=words->end())
{
cout<<(*words)<<endl;
iter++;
}
}
TextQuery::strip_lines()
{
vector<string,allocator<string> >* words=new vector<string>;
vector<Location,allocator<Location> >* locations=new vector<Location>;
vector<string,allocator<string> >::iterator iter=lines_of_text->begin();
while(iter!=lines_of_text->end())
{
short line_no=0;
string::size_type pos=0,prev_pos=0;
line_no++;
string textline=(*iter);
cout<<textline;
iter++;
short word_cnt=0;
string word;
while((pos=textline.find_first_of(' ',prev_pos))!=string::npos)
{
word_cnt++;
word=textline.substr(prev_pos,pos-prev_pos);
words->push_back(word);
locations->push_back(make_pair(line_no,word_cnt));
pos++;
prev_pos=pos;
}
words->push_back(word);
word_cnt++;
locations->push_back(make_pair(line_no,word_cnt));
}
wordLocations=new WordLocations(words,locations);
}
TextQuery::retrieve_text()
{
lines_of_text=new vector<string,allocator<string> >;
string file_name;
cout<<"enter the file name: ";
cin>>file_name;
fstream infile(file_name.c_str(),ios::in);
if(!infile)
cout<<"not file found"<<endl;
string textline;
while(getline(infile,textline,'\n'))
{
lines_of_text->push_back(textline);
}
}
TextQuery::display_lines_of_text()
{
vector<string,allocator<string> >::iterator iter=lines_of_text->begin();
while(iter!=lines_of_text->end())
{
cout<<(*iter)<<endl;
iter++;
}
}
};
---------------------------------
Yahoo! for Good
Click here to donate to the Hurricane Katrina relief effort. |