Answers for "C++ stl vector basic"

C++
0

C++ stl vector basic

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector<int> v;
    vector<int> a(5,1);
    vector<int> last(a);
    cout<<"Print last"<<endl;
    for(int i:last){
        cout<<i<<" ";
    }cout<<endl;
    cout<<"capacity "<<v.capacity()<<endl;
    v.push_back(1);
    cout<<"capacity "<<v.capacity()<<endl;
    v.push_back(2);
    cout<<"capacity "<<v.capacity()<<endl;
    v.push_back(3);
    cout<<"capacity "<<v.capacity()<<endl;
    cout<<"size "<<v.size()<<endl;
    cout<<"Element at second index "<<v.at(2)<<endl;
    cout<<"front "<<v.front()<<endl;
    cout<<"back "<<v.back()<<endl;
    
   
}
Posted by: Guest on September-11-2021

Browse Popular Code Answers by Language