First for loop
int i;
for (i = 0; i <= vec.size(); i++) {
if (vec.size() == 0) {
cout << "[] The list is Empty" << endl;
} else {
cout << vec[i] << " ";
}
}
}
Second for loop
cout << "[ "; for(auto num : vec) cout << num << " "; cout << "]";
Why is it that when I display all the elements in a vector using the first for loop I get "0" at the end of the vector. However, when I use the range for loop, I do not get the zero.
vec.size()gives you unsigned int - dgrandm