Hi, I'm trying to learn C++ and I am currently studying vector arrays. I am confused by which the book is teaching me how to work with vector arrays. In my book, it says to type these codes;
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector <int> vec(3, 100);
vec.pop_back(); // Removes the final element
cout << "Vector size: " << vec.size() << endl;
cout << "Final element: " << vec.back() << endl;
vec.clear(); //Remove all elements
cout << "Vector size: " << vec.size() << endl;
So why is it that the output for this is Vector size: 2 and Final element: 100, when you remove the final element using pop_back();? Are all three of these values in this vector array 100?
Also, why is the out put for this Vector size: 0, when you use the clear()? doesn't this clear the values in this array and the size should remain the same (size 3)?
I apologize if these questions may seem ridiculous, but the book that I have doesn't do a good job in articulating the example they have me to do.