explicit vector (size_type n, const T& value= T(), const Allocator& = Allocator());
constructeur de séquence Répétitif: Initialise le vecteur avec son ensemble de contenu à une répétition, n
fois, des copies de value
.
vector< vector<int> > vI2Matrix(3, vector<int>(2,0));
Crée 3 vecteurs avec 2 zéros chacun. Essentiellement, on utiliserait un vecteur de vecteurs pour représenter un réseau bidimensionnel.
Voici un exemple de code source:
#include <iostream>
#include <vector>
using namespace std;
main()
{
// Declare size of two dimensional array and initialize.
vector< vector<int> > vI2Matrix(3, vector<int>(2,0));
vI2Matrix[0][0] = 0;
vI2Matrix[0][1] = 1;
vI2Matrix[1][0] = 10;
vI2Matrix[1][1] = 11;
vI2Matrix[2][0] = 20;
vI2Matrix[2][1] = 21;
cout << "Loop by index:" << endl;
int ii, jj;
for(ii=0; ii < 3; ii++)
{
for(jj=0; jj < 2; jj++)
{
cout << vI2Matrix[ii][jj] << endl;
}
}
return 0;
}