vector<int> nums{1,2,3,0,0,0};
for(int i = 0; i< nums.size(); i++){
if(nums[i] == 0){
nums.erase(nums.begin() + i);
}
}
for(int i = 0; i< nums.size(); i++){
cout << nums[i] << " ";
}
//I keep getting [1, 2, 3, 0]
I want to remove the zeros from the vector so that I only have 1,2,3 left over. However, the method I'm using seems to keep leaving one zero at the end. I've been at it for a while and I've played with the indexing but I can't seem to get it to work correctly. I'd appreciate help thanks.