这个迭代器声明有什么问题
What's wrong with this iterator declaration
我在我的类中有一个方法,它是:
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 setn";
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] );
}
}
,当我试图构建它时,我被告知不可能将"std::ifstream"转换为"std::basic_istream<_Elem,_Traits> &"?这意味着什么,我该做什么(除了深入研究迭代器,也就是;-))?
您有错误,因为您使用diff_type
作为second
模板参数。如果你想使用diff_type
,你应该正确地声明istream_iterator
,声明应该是
istream_iterator<string, char, std::char_traits<char>, diff_type>
既然istream_iterator
真的是
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT>,
class Distance = std::ptrdiff_t >
class istream_iterator
你可以在这里看到
相关文章:
- 警告处理为错误这里有什么问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 当我尝试添加 2 个大字符串时,我无法弄清楚出了什么问题
- 违反const正确性:我应该现实地期待什么问题
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- 我的逻辑反转字符串中的元音有什么问题?
- 需要以下代码的帮助,下面的代码有什么问题
- 常量公共成员有什么问题?
- 以下代码中的函数模板有什么问题?
- 这个返回元素位置的基于循环的函数有什么问题?
- creat_list2功能有什么问题?
- 格式说明符C++有什么问题
- 任何人都可以告诉我我的 C++ 代码出了什么问题?
- 从 argv[1] 转换为字符 * 字符串后有什么问题?
- 我的堆栈和库存清单程序的结构有什么问题?
- 此工厂功能有什么问题?
- 以下 C++ 代码有什么问题?
- 数组为此合并排序函数提供了正确的输出,但向量给出了不正确的输出.出了什么问题?
- reinterpret_cast,只读访问,简单的可复制类型,会出什么问题?
- 它解决了什么问题,对于非真空初始化,生命周期在初始化之前就开始了