I wrote a small program to remove 0's from a vector. But when I check, there is still a zero in the vector. why?
The size says its 4 when it should be 3 and there is still a zero showing.
int main()
{
vector<int> nums1 = {1, 2, 3, 0, 0, 0};
for(int i=0; i< nums1.size(); i++)
{
if(nums1[i] == 0)
nums1.erase(nums1.begin() + i);
}
cout << "size is now: " << nums1.size() << endl;
for(int j=0; j<nums1.size(); j++)
cout<< nums1[j] << endl;
return 0;
}