For example:
#include<vector> using namespace std; int main() { vector<int[]> vec;//serious compiler error vector<int[2]> vec={{1,2}};//error:array must be initialized with a brace-enclosed initializer } In addition, how to rectify the grammar of the second one? I already use a brace-enclosed initializer.
vectormust be fixed at compile time. In an array, the size is part of the type. If you want something that is conceptually a "variable-length array", that is exactly whatvectoris for!vector<array<int,2>>for the second one.