vector operations in c++ code example

Example 1: c++ vector

#include 

int main() {
  std::vector v;
  v.push_back(10); // v = [10];
  v.push_back(20); // v = [10, 20];
  
  v.pop_back(); // v = [10];
  v.push_back(30); // v = [10, 30];
  
  auto it = v.begin();
  int x = *it; // x = 10;
  ++it;
  int y = *it; // y = 30
  ++it;
  bool is_end = it == v.end(); // is_end = true
  
  return 0;
}

Example 2: vector operations in c++

#include 
#include
#include

using namespace std;

int main()
{
    int n;
    cin>>n;
    vectorvec(n);
    for(int i=0;i>vec[i];
    }
    cout<<"----------"<::iterator it1=vec.begin();it1!=vec.end();it1++)
    {
        cout<<*it1<<" ";
    }
    cout<vec2;
    vec2.push_back(15);
    vec2.push_back(25);
    vec2.push_back(35);
    vec.insert(it,vec2.begin(),vec2.end());
    for(vector::iterator it1=vec.begin();it1!=vec.end();it1++)
    {
        cout<<*it1<<" ";
    }
    cout<::iterator it1=vec.begin();it1!=vec.end();it1++)
    {
        cout<<*it1<<" ";
    }
    cout<>k;
    cout<::iterator its=vec.begin()+k-1;
    int s=vec.size();
    cout<::iterator it1=vec.begin();it1!=vec.end();it1++)
    {
        cout<<*it1<<" ";
    }
    

    return 0;
}

Tags:

Misc Example