下面摘自c++primer3rd第三版第263页至264页中原文-》是不是有错?
void TextQuery::
build_word_map()
{
word_map = new map< string, loc*, less<string>, allocator >;
typedef map<string,loc*,less<string>,allocator>::value_type
value_type;
typedef set<string,less<string>,allocator>::difference_type
diff_type;
set<string,less<string>,allocator> 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;
copy( input_set, eos,
inserter( exclusion_set, exclusion_set.begin() ));
}
// 遍历单词, 输入键/值对
vector<string,allocator> *text_words = text_locations ->first;
vector<location,allocator> *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>;
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] );
}
}
上面代码摘自 c++primer3rd第三版 pdf格式第263页至264页(第6章抽象容器类型最后完整程序中TextQuery类的成员函void
TextQuery:: build_word_map()
其中,红色部分(也就是下面一行
istream_iterator< string, diff_type >
)这半个语句是不是有错?我怎么也看不懂。调试也不行。只有把后面的(, diff_type)去掉才能调试成功,所以我猜是不是书上写错了?去掉 (, diff_type)后对程序有没有影响?有什么影响?
在几个地方都看见有这种说法,说 istream_iterator 只支持单一类型,是这样吗?我猜,如果真是只支持单一类型,那么应该是书上写错了。到现在我可以确定书上有几处错了,但这里我不知道,请高手指教。
请不要叫我百度。我百度了很多次了。 也请不要复制粘贴。谢谢。