让我们来看看:
x = list<int>::iterator
y = list<int>::const_iterator
z = vector<int>::iterator
t = vector<int>::const_iterator
之间有什么区别:
++x
和x++
?++y
和y++
?++z
和z++
?++t
和t++
?答案 0 :(得分:0)
++ x比x ++更有效,因为x ++首先创建一个临时对象。
另外,如果你在赋值语句中使用它会有区别,就像你说的那样整数
int x = 8;
int y;
y = x++;//y will be 8
y = ++x;//y will be 10
类似地,如果您访问这样的迭代器,pre increment将首先指向下一个迭代器,然后执行其他操作。如果后增量,则将访问当前的电流,然后递增。