首页 > 解决方案 > 顺序评估前后迭代器增量

问题描述

对不起。我应该改变我的问题。我有以下代码

std::vector<int> v = {10, 20, 30};
auto it = v.begin();

std::cout << *it++ << std::endl;    // 1. no parenthesis

std::cout << *(it++) << std::endl;  // 2. with parenthesis

it++;                               // 3. post-increment first
std::cout << *it << std::endl; 

std::cout << *(it + 1) << std::endl;// 4. increment index

以上4种说法有什么区别?括号在后增量中重要吗?除了 2(带括号)之外,所有输出都与我的预期相同。

标签: c++iteratorincrement

解决方案


推荐阅读