我知道如何像这样初始化一维 vector
int myints[] = {16,2,77,29};
std::vector<int> fifth(myints, myints + sizeof(myints) / sizeof(int));
假设我有2D数据。
float yy[][2] = {{20.0, 20.0}, {80.0, 80.0}, {20.0, 80.0}, {80.0, 20.0}};
如何初始化2D vector ?
最佳答案
在C++ 11中,您可以像这样初始化 vector 的 vector :
auto yy = std::vector<std::vector<float>>
{
{20.0, 20.0},
{80.0, 80.0},
{20.0, 80.0},
{80.0, 20.0}
};