看过C++ Primer的过来帮帮我!

weixiaohua 2004-04-08 03:16:47
第六章最后那个例子!

这是出现错误代码的地方:
void TextQuery::build_word_map()
{
word_map = new map<string, loc*, less<string>, allocator<string> >;
typedef map<string, loc*, less<string>, allocator<string> >::value_type value_type;
typedef set<string, less<string>, allocator<string> >::difference_type diff_type;
set<string, less<string>, allocator<string> > exclusion_set;
ifstream infile("exclusion_set");
if(!infile)
{
static string default_excluded_words[25] = {"the", "and", "but", "that", "then", "are", "been", "can",
"can't", "cannot", "could", "did", "for", "had", "have", "him", "his", "her", "its", "into",
"were", "which", "when", "with", "would"};
cerr << "warning! unable to open word exclusion file! -- " << "using default set\n";
copy(default_excluded_words, default_excluded_words + 25, inserter(exclusion_set, exclusion_set.begin()));
}
else
{
istream_iterator<string, diff_type> input_set(infile), eos; //这里有错误!
//错误提示: 198 C:\Documents and Settings\Administrator\My Documents\Untitled2.cpp
//no matching function for call to `std::istream_iterator<std::string, diff_type,

copy(input_set, eos, inserter(exclusion_set, exclusion_set.begin()));
}
vector<string, allocator<string> > *text_words = text_locations->first;
vector<location, allocator<string> > *text_locs = text_locations->second;
register int elem_cnt = text_words->size();
for(int ix=0; ix<elem_cnt; ++ix)
{
string textword = (*text_words)[ix];
if((textword.size() < 3) || exclusion_set.count(textword))
continue;

if(!word_map->count((*text_words)[ix])) {
loc *ploc = new vector<location, allocator<string> >;
ploc->push_back((*text_locs)[ix]);
word_map->insert(value_type((*text_words)[ix], ploc));
}
else (*word_map)[(*text_words)[ix]]->push_back((*text_locs)[ix]);
}
}

各位一定要帮帮我啊!
...全文
37 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsdkzkald 2004-04-09
  • 打赏
  • 举报
回复
路过学习
古布 2004-04-08
  • 打赏
  • 举报
回复
遇到过,为分配器加上名字空间就好了:
几凡是allocator的地方都加上std::,如:
word_map = new map<string, loc*, less<string>, allocator<string> >;
                      ^^^^^^^^^^^
std::allocator<string>  
ut1949 2004-04-08
  • 打赏
  • 举报
回复
太长了
vhikyh 2004-04-08
  • 打赏
  • 举报
回复
没仔细看,估计你哪里敲错了。我以前也敲了一边,编译时一堆错误,不过都是我自己敲错的。
建议仔细看看!!!!!!
weixiaohua 2004-04-08
  • 打赏
  • 举报
回复
我加了啊!
bm1408 2004-04-08
  • 打赏
  • 举报
回复
加上:

using namespace std;
weixiaohua 2004-04-08
  • 打赏
  • 举报
回复
第六章最后面那个例子啊!
binjuny 2004-04-08
  • 打赏
  • 举报
回复
你说在那一面,我们自己去看吧
weixiaohua 2004-04-08
  • 打赏
  • 举报
回复
晕死,贴出来怎么这么乱了!

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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