I have a vector with {}
initializer. And then I use push_back
to add an element into the vector.
When I print the vector elements, the pushed element does not print. Why is that?
int main() {
vector<int> vec = {0,1,2,3,4,5,6,7,8,9};
vec.push_back(1);
cout << "size = " << vec.size() << endl;
cout << "vals: ";
for (auto &v : vec) {
cout << v << "\t" ;
}
}
Output:
Value 1 should be printed, but it does not.
size = 11
vals: 0 1 2 3 4 5 6 7 8 9