Explicit initializer_list Usage - C++ STL

C++ examples for STL:vector

Description

Explicit initializer_list Usage

Demo Code

#include <iostream>
#include <vector>

using namespace std;

int main()/* w  w  w  . jav a  2s.c  o  m*/
{
    using MyVector = vector<int>;

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

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

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

    return 0;
}

Result


Related Tutorials