如何获取vector的一个迭代器iterator的地址 |
您所在的位置:网站首页 › std容器取地址 › 如何获取vector的一个迭代器iterator的地址 |
在使用vector时,使用*iterator可以读出迭代器指向vector中的值,那如果想读出iterator的地址,该怎么表示呢? 思考对于常规的指针而言,可以用int *ptr来表示一个指向整型变量的指针,*ptr即指向整型变量的值,ptr即地址 代码如下 #include using namespace std; int main(){ int i = 123; int *ptr; ptr = &i; cout vecInt.push_back(i); } //show all elements cout /* want to get the address of iterator cout vector vecInt; for(int i = 10; i != 15; i++){ vecInt.push_back(i); } //address of iter and end vector::iterator iter = vecInt.begin(); while(iter != vecInt.end()){ cout |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |