大佬教程收集整理的这篇文章主要介绍了c – 迭代对的向量,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
int main(){ int VCount,v1,v2; pair<float,pair<int,int> > edge; vector< pair<float,int> > > edges; float w; cin >> VCount; while( cin >> v1 ){ cin >> v2 >> w; edge.first = w; edge.second.first = v1; edge.second.second = v2; edges.push_BACk(edgE); } sort(edges.begin(),edges.end()); for ( vector < pair<float,int>> >::const_iterator it = edges.begin() ; itt != edges.end; it++){ cout >> it.first; } return 0; }
error: no match for ‘operator<’ in ‘it < edges.std::vector<_Tp,_Alloc>::end [with _Tp = std::pair<float,std::pair<int,int> >,_Alloc = std::allocator<std::pair<float,int> > >,std::vector<_Tp,_Alloc>::const_iterator = __gnu_cxx::__normal_iterator<const std::pair<float,int> >*,std::vector<std::pair<float,int> > > >,typename std::_Vector_base<_Tp,_Alloc>::_Tp_alloc_type::const_pointer = const std::pair<float,int> >*]
谁能帮我吗?
for ( vector < pair<float,int>> >::const_iterator it = edges.begin() ; itt != edges.end; it++){ cout >> it.first; }
首先,你必须使用edges.end()而不是edges.end.身体内部必须有
cout << it->first;
代替
cout >> it.first;
要逃避这些错误,你可以简单地写一下
for ( const pair<float,int> > &edge : edges ) { std::cout << edge.first; }
以上是大佬教程为你收集整理的c – 迭代对的向量全部内容,希望文章能够帮你解决c – 迭代对的向量所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。