| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 562 人关注过本帖
标题:[求助]C++Primer上的一个例题分析
只看楼主 加入收藏
Powerqy
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2007-3-30
收藏
 问题点数:0 回复次数:0 
[求助]C++Primer上的一个例题分析

#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 );

}
调试也通不过?
谢谢大家指教!

搜索更多相关主题的帖子: 例题 Primer 
2007-07-27 09:43
快速回复:[求助]C++Primer上的一个例题分析
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013837 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved