I'm trying to change the values of a vector by doing something similar to the following function:
vector<int> Question2_Part3(vector<int> &v){
for(auto elem : v){
elem *= 2;
cout << elem << " ";
}
cout << "
" << endl;
return v;
}
Is this possible? I know that in my for loop, it is the value of elem
that is changing. Can I have the same output while also changing the values in v
and still use a range-based for loop?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…