vector问题??

ayiayi6386 2003-08-23 11:28:07
//这是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 ]我不懂!
...全文
25 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

69,364

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧