vector + vector code example
Example 1: c++ vector
#include <vector>
int main() {
std::vector<int> v;
v.push_back(10);
v.push_back(20);
v.pop_back();
v.push_back(30);
auto it = v.begin();
int x = *it;
++it;
int y = *it;
++it;
bool is_end = it == v.end();
return 0;
}
Example 2: get values from a vector of vectors c++
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<int> > buff;
for(int i = 0; i < 10; i++)
{
vector<int> temp;
for(int j = 0; j < 10; j++)
temp.push_back(i);
buff.push_back(temp);
}
for(int i = 0; i < buff.size(); ++i)
{
for(int j = 0; j < buff[i].size(); ++j)
cout << buff[i][j];
cout << endl;
}
return 0;
}
Example 3: how to create a vector from elements of an existing vector in cpp
vector<int> vect1{1, 2, 3, 4};
vector<int> vect2;
vect2.assign(vect1.begin(), vect1.end());