Search on the blog


A few types of vector constructors

Here are some vector constructors I show you today.
  1. default constructor
  2. copy constructor
  3. initializing constructor
The first one is pretty simple:
vector<int> x;
Nothing special.

The second one is also a famous type of constructor:
vector<int> x;

vector<int> y(x.begin(), x.end());
REP(i, y.size())
cout << y[i] << endl;
With it, you can copy the contents of another vector. In the example above, you'll get a new vector y, whose contents is copied from vector x.

The last but not least is the initializing constructor. Literally you can initialize vectors at the same time as declaring them.
vector<int> x(10, 0);
You're creating a vector whose value is composed of 10 zeros.

0 件のコメント: