I am learning C ++ as a beginner (I started 2 months ago) and I have a problem with my simple code. I tried to set the value of each element in this vector to 0, but I can not understand why it does not work:
vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (int x : numbers) x = 0;
I know that I may seem stupid, but I'm new. If I try to do the same with traditionally for the loop, it works, why?
source
share