#include <vector>
#include <string>
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 )
{
// words: 包含独立单词的集合
// locations: 包含相关的行/列信息
vector<string> *words = new vector<string>;
vector<location> *locations = new vector<location>;
short line_pos = 0; // current line number
// iterate through each line of text
for ( ; line_pos < text_file->size(); ++line_pos )
{
// textline: 待处理的当前文本行
// word_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 ));
// 将行/列信息存储为pair
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 );
}
int main()
{
vector *text_fo;e = retroeve_text);//这里不知道是怎么回事?
text_loc *text_locations = separate_words( text_file );
}
调试也通不过?
谢谢大家指教!