Regarding the final code example,
you can't have this statement outside a function body:
std::newvector.push_back(5);
Place it in main
's function body, and remove the std::
prefix.
Also note that for this vector modification to be possible, the vector can't be const
.
Initialization with round parentheses provides arguments to a constructor for the class. There must be a corresponding constructor. And there is no std::vector
constructor that corresponds to the four arguments in
vector <int> myVector (5,4,3,4);
Instead do
vector <int> myVector = {5,4,3,4};
If your compiler supports this C++11 syntax, that is.
If not, then the C++03 way would be
static int const data[] = {5,4,3,4};
static int const n_items = sizeof(data)/sizeof(data[0]);
vector <int> myVector( data, data + n_items );