且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何初始化 std::vector 数组?

更新时间:2023-11-10 23:09:04

在 C++11 中,

type vecAry[] {{},{},{}};

或者如果你想要非空向量

or if you want non-empty vectors

type vecAry[] {{1,2,3},{4,5,6},{7,8,9}};

如果你被困在过去,你可以用空向量初始化它:

If you're stuck in the past, you can initialise it with empty vectors:

type vecAry[] = {type(), type(), type()};

但是如果没有像 Boost 赋值库:

type vecAry[] = {list_of(1)(2)(3), list_of(4)(5)(6), list_of(7)(8)(9)};