我在从链接列表中的项目中获取一些地址时遇到了一些麻烦。而不是在 for 循环开始时创建和初始化的迭代器地址,我想获取位于列表中的实际数据的地址。如果不创建我自己的列表实现,这可能吗?这是我得到的代码块,但显然它没有按照我想要的方式工作。
int j = 0;
testIntList.resize(100);
for (list<int>::iterator i = testIntList.begin(); i != testIntList.end(); ++i) {
*i = j*j;
int * k = &(*i);
cout << "the value of the iterator is " << *i << " and the address of the iterator is " << &i << "and the address of the pointer is " << *k << endl;
j++;
}
我以这种方式使用 k 来尝试获取内存中迭代器值地址的实际指针。任何帮助将不胜感激。