我知道如何初始化这样的1d矢量
int myints[] = {16,2,77,29};
std::vector<int> fifth(myints, myints + sizeof(myints) / sizeof(int));
Run Code Online (Sandbox Code Playgroud)
假设我有2d数据.
float yy[][2] = {{20.0, 20.0}, {80.0, 80.0}, {20.0, 80.0}, {80.0, 20.0}};
Run Code Online (Sandbox Code Playgroud)
如何初始化2d向量?
在当前的C++中(自2011年起),您可以在构造函数中初始化此类向量:
vector<vector<float>> yy
{
{20.0, 20.0},
{80.0, 80.0},
{20.0, 80.0},
{80.0, 20.0}
};
Run Code Online (Sandbox Code Playgroud)
看到它活着:http://ideone.com/GJQ5IU.
| 归档时间: |
|
| 查看次数: |
4502 次 |
| 最近记录: |