使用大括号符号C++填充动态数组
Fill dynamic array using curly bracket notation C++
c++中有没有一种方法可以填充像这样分配的数组
int **a = new int[4][2];
这样就可以像一样在一行中填充值
int a [4][2] = {{2,3,4},{5,6,7}};
您可以在C++11中使用通用初始化表示法:
int(*a)[2] = new int[2][2]{{1,2},{3,4}};
一个向量的向量可以工作,但只能在C++11中工作。我想你必须放弃的C兼容性
#include <vector>
int main()
{
std::vector<std::vector<int>> v = {{2,3,4},{5,6,7}};
}
如果编译器有足够的C++11支持,则首选std::array而不是C样式数组:
#include <array>
int main()
{
std::array<std::array<int,3>,3> v = {1,2,3,4,5,6,7,8,9};
}
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用用户输入在C++中正确填充2D数组
- 如何找到大小'x'数组是否完全填充,在C++?
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 通过for循环使用用户输入填充列表
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 如何正确填充在堆上分配的二维数组?
- 将数字转换为填充字符串
- 有没有办法在一行中填充矢量图
- 用C++中的数字和条件填充向量
- 用真值填充矢量
- 使用结构成员指针在C++中填充结构
- 流填充字符的默认定位
- 使用不同算法的 PKCS1v15 填充进行加密 ++ 签名
- C++:使用缓冲区中的数据填充结构
- 如何将零填充的多维数组传递给 C++ 中的函数?
- Cryptopp:获取密码输入的填充字符串
- 填充上编译器生成的复制构造函数之间的不一致
- RcppEigen 模板化函数,用于填充单位法线
- 我想生成许多矩阵并用随机数填充它