vector问题??
//这是c++primer vector章节,我的问提在最后面请你给我讲讲好吗?
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 );
}
我的问题:
string textline = (*text_file)[ line_pos ];
(*text_file)[ line_pos ]我不懂!