这个函数有问题吧?
#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef pair<short,short> location;
typedef vector<location> loc;
typedef vector<string> text;
typedef pair<text*,loc*> text_loc;
text_loc* separate_words(const vector<string> *text_file)
{
vector<string> *words=new vector<string>;
vector<location> *locations =new vector<location>;
short line_pos=0;
for(; line_pos < text_file->size(); ++line_pos)
{
short word_pos=0;
string textline=(*text_file)[line_pos];
string::size_type pos =0 ,prev_pos=0;
while(( pos=textline.find_first_of(' ',pos)) !=string::npos)
{
words->push_back( textline.substr(prev_pos, pos-prev_pos));
locations->push_back( make_pair(line_pos,word_pos));
++word_pos; prev_pos=++pos;
}
words->push_back( textline.substr(prev_pos,pos-prev_pos));
locations->push_back( make_pair(line_pos,word_pos));
}
return new text_loc(words,locations);
}
这里是不是有问题??
words->push_back( textline.substr(prev_pos,pos-prev_pos));