如何使用迭代器引用向量中元素的地址。
vector<Record>::const_iterator iter = collectionVector.begin();
while(iter != collectionVector.end())
{
//How can I refer to the address of a Record here
function(...); //accepts &Record type
}
答案 0 :(得分:2)
您可以使用&(*iter)
获取地址。以下是示例代码:
std::vector<int> a;
a.push_back(1);
std::vector<int>::iterator iter = a.begin();
int *p = &(*iter) ;
*p =10;