C++ 什么';It’这个迭代器声明有什么问题
我班上有一个方法,它是:C++ 什么';It’这个迭代器声明有什么问题,c++,istream-iterator,C++,Istream Iterator,我班上有一个方法,它是: 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
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;
copy( input_set, eos, inserter( exclusion_set, exclusion_set.begin() ));
}
vector<string,allocator<string> > *text_words = text_locations->first;
vector<location,allocator<location> > *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<location> >;
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] );
}
}
void TextQuery::build\u word\u map()
{
word_map=新地图;
typedef映射::值\类型值\类型;
typedef set::difference_type diff_type;
集合排除集;
如果流填充(“排除集”);
如果(!infle)
{
静态字符串默认值\u排除\u单词[25]={“the”,“and”,“but”,“that”,“then”,“are”,“been”,“can”,“can”,“can”,“can”,“did”,“for”,
“had”,“have”,“him”,“his”,“her”,“its”,“into”,“were”,“which”,“when”,“with”,“will”};
cerr第二;
register int elem_cnt=text_words->size();
对于(int-ix=0;ix计数((*文本单词)[ix]))
{
loc*ploc=新载体;
ploc->推回((*文本位置)[ix]);
单词映射->插入(值类型((*文本单词)[ix],ploc));
}
else(*word_map)[(*text_words)[ix]]->推回((*text_locs)[ix]);
}
}
,当我尝试构建它时,我被告知不可能将“std::ifstream”转换为“std::basic_istream&”?
这意味着什么,我该怎么做(除了深入研究迭代器,即;-)?您有错误,因为您使用
diff_type
作为第二个模板参数。
如果您想使用diff\u type
您应该正确地声明istream\u迭代器
,声明应该是
istream_iterator<string, char, std::char_traits<char>, diff_type>
正如您所看到的,您有错误,因为您使用了diff_type
作为second
模板参数。
如果您想使用diff\u type
您应该正确地声明istream\u迭代器
,声明应该是
istream_iterator<string, char, std::char_traits<char>, diff_type>
如您所见您能给出准确的错误吗?请您能给我们一个最小的崩溃代码,以及出现错误的行吗?您的分配器类型错误。错误C2664:std::istream\u迭代器::istream\u迭代器(std::basic\u istream&):无法将参数1从“std::ifstream”强制转换为“std::basic\u istream&”1>,带1>[1>\u Ty=std::string,1>\u Elem=diff\u type,1>\u Traits=std::char\u Traits 1>]1>和1>[1>\u Elem=diff\u type,1>\u Traits=std::char\u Traits 1>]是的,我知道它应该是wron迭代器,但不知怎么的,如果流迭代器在我的IDE中没有被识别。你能给出确切的错误吗?请你给我们一个最小的崩溃代码,以及错误出现的行吗?你的分配器是错误的类型。错误C2664:std::istream\u迭代器::istream\u迭代器(std::basic\u istream&):无法将参数1从“std::ifstream”强制转换为带有1>[1>\u Ty=std::string、1>\u Elem=diff\u type、1>\u Traits=std::char\u Traits 1>]1>和1>[1>\u Elem=diff\u type、1>\u Traits=std::char\u Traits 1>]是的,我知道它应该是wron迭代器,但不知何故,ifstream_迭代器在我的IDE中没有被识别。这确实有效)谢谢。关于如何避免将来出现此类错误的任何提示?这确实有效)谢谢。关于如何避免将来出现此类错误的任何提示?