Using Uniform Initialization to Construct a vector - C++ STL

C++ examples for STL:vector

Description

Using Uniform Initialization to Construct a vector

Demo Code

#include <iostream>
#include <vector>

using namespace std;

int main()//from ww w .j  av a 2s .  com
{
    using MyVector = vector<int>;

    MyVector vectorA( 1 );
    cout << vectorA.size() << " " << vectorA[0] << endl;

    MyVector vectorB( 1, 10 );
    cout << vectorB.size() << " " << vectorB[0] << endl;

    MyVector vectorC{ 1, 10 };
    cout << vectorC.size() << " " << vectorC[0] << endl;

    return 0;
}

Result


Related Tutorials