1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#include <iostream>
#include <vector>
#include <algorithm>
void print( const std::vector< std::vector<int> >& vov )
{
for( const auto& vec : vov )
{
std::cout << "[ " ;
for( int value : vec ) std::cout << value << ' ' ;
std::cout << "]\n" ;
}
std::cout << "---------\n" ;
}
int main()
{
// create a vector of vectors initially containing three empty vectors
std::vector< std::vector<int> > vov(3) ;
print(vov) ;
// push back the vector [ 6, 7, 8, 9, 1, 2, 3 ]
vov.push_back( { 6, 7, 8, 9, 1, 2, 3 } ) ;
print(vov) ;
vov[2].push_back(7) ; // push back 7 to vov[2]
vov[1] = { 9, 3, 5, 2, 9, 7 } ; // replace vov[1]
vov.front().resize( 10U, 8 ) ; // resize vov[0]
print(vov) ;
std::sort( std::begin(vov), std::end(vov) ) ; // sort vov
print(vov) ;
// etc.
}
|