【发布时间】:2015-07-31 14:48:04
【问题描述】:
出于测试目的,我通过for 循环运行以下代码。实际上只有前三个键存在,并且 “Record found” 与从 findVertex->first 检索的键一起按预期显示。
- 我的问题是,我如何才能访问指向的第二个值?
findVertex->second似乎很明显,但不起作用,因为第二个值是我创建的对象,如果它有任何用处,它的声明在代码下方给出。
for(int i = 0; i<10; i++)
{
map<int, vector<Vertex> >::const_iterator findVertex = vertexMap.find(i);
if(findVertex != vertexMap.end())
{
cout<<"\nRecord found: ";
cout<<findVertex->first;
cout<<findVertex->second; //does not work
}
else
cout<<"\nRecord not found";
}
类代码:
class Vertex
{
private:
int currentIndex;
double xPoint, yPoint, zPoint;
vector<double> attributes;
public:
friend istream& operator>>(istream&, Vertex &);
friend ostream& operator<<(ostream&, Vertex &);
};
谢谢
【问题讨论】:
-
提供运营商:
std::ostream& operator << (std::ostream&, const std::vector<Vertex>&)
标签: c++ dictionary stl iterator iostream