I have a std::vector<int> and I want to modify subset of the elements. I thought I might be able to use:
1 2 3 4 5 6 7 8
std::vector<int> a = { 1,2,3,4,5,6,7,8,9 };
std::vector<int> b(&a[3],&a[7]);
for(auto& each : b) {
each++;
}
for(auto& each : a) {
std::cout << each << "\n";
}
but that didn't work. The elements of 'a' retain their original values. Then, I thought, "Ooo, maybe I could make 'b' a reference." Nope. What approach would You suggest in accessing a subset of a vector for potential alteration?