c++使用 vector指针访问vector元素时,不能简单的类似于c中数组和指针的方式。需要使用迭代器。
int main()
{
vector<int> s;
vector<int> *p = &s;
s.push_back(1);
for (vector<int>::iterator it = p->begin(); it != p->end(); it++)
cout << *it<<endl; //使用迭代器,正确
cout << p[0] << endl; //错误
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)