【发布时间】:2019-01-05 10:18:05
【问题描述】:
我们知道 cpp 中的迭代器指向容器的某个元素,就像我们谈论向量一样
vector <int> v = {1,2,3,4,5}
vector<int>::iterator ptr;
ptr=v.begin();
ptr 将指向第一个内存块,例如 200 让我们声明另一个迭代器
vector<int>::iterator ptrend;
ptrend=v.end()
which point to just next follow of last element say will
be equal to 220
我的疑惑
1) 我们知道v.end()-v.begin() = v.size()
但在我们的案例中并非如此220 -200 =20 != size
2) 比如说vector<int>::iterator ptr=v.begin();
在这里我们可以分配这样的东西ptr = &a[3]
【问题讨论】:
-
欢迎来到 Stack Overflow!请使用tour 并阅读How to Ask。关于你的问题,有一个特别的错误:你问了两个问题,这通常是不好的。
-
但你还是回复了 :p 但我同意你的回答 ;)
-
这似乎很方便,因为这两个问题或多或少都基于相同的有缺陷的假设。