对于单个矢量,您可以使用以下内容:
typedef int type;
type elements[] = {0,1,2,3,4,5,6,7,8,9};
vector<int> vec(elements, elements + sizeof(elements) / sizeof(type) );
Run Code Online (Sandbox Code Playgroud)
基于此,您可以使用以下内容:
type matrix[2][2]=
{
{1,0},{0,1}
};
vector<int> row_0_vec(matrix[0], matrix[0] + sizeof(matrix[0]) / sizeof(type) );
vector<int> row_1_vec(matrix[1], matrix[1] + sizeof(matrix[1]) / sizeof(type) );
vector<vector<type> > vectorMatrix;
vectorMatrix.push_back(row_0_vec);
vectorMatrix.push_back(row_1_vec);
Run Code Online (Sandbox Code Playgroud)
在c ++ 0x中,您可以以与数组相同的方式初始化标准容器.
| 归档时间: |
|
| 查看次数: |
32765 次 |
| 最近记录: |