Can I initialize an STL vector with 10 of the same integer in an initializer list?

后端 未结 6 1723
遇见更好的自我
遇见更好的自我 2021-01-31 07:54

Can I initialize an STL vector with 10 of the same integer in an initializer list? My attempts so far have failed me.

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 08:14

    If you're using C++11 and on GCC, you could do this:

    vector myVec () {[0 ... 99] = 1};
    

    It's called ranged initialization and is a GCC-only extension.

提交回复
热议问题