对我来说,这不会产生预期的结果:
int main() {
int i[12] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
for (auto v : i)
std::cout << v << std::endl;
for (auto v : i)
v = v+1;
for (auto v : i)
std::cout << v << std::endl;
return 0;
}
第二个for
循环似乎没有做任何事情。基于范围的for
循环是只读的,还是我遗漏了什么?