What is the easiest way to initialize a std::vector with hardcoded elements?

后端 未结 29 3281
终归单人心
终归单人心 2020-11-22 05:07

I can create an array and initialize it like this:

int a[] = {10, 20, 30};

How do I create a std::vector and initialize it sim

29条回答
  •  庸人自扰
    2020-11-22 05:30

    typedef std::vector arr;
    
    arr a {10, 20, 30};       // This would be how you initialize while defining
    

    To compile use:

    clang++ -std=c++11 -stdlib=libc++  
    

提交回复
热议问题