将数组转换为矢量
converting array to vector
将
int 数组转换为 vector 的最简单方法是什么?并将其与 if 语句一起使用。
即
int num1[4] = {2, 4, 1, 8};
int num2[4] = {2, 4, 6, 8};
if (testNUM(num1, num2, 4))
cout << "ERROR: num1 and num2 are reported to be the same.n";
else
cout << "SUCCESS: num1 and num2 are correctly identified "
<< "as different.n";
testNUM 被声明为函数原型 (BOOL)。
谢谢
这是将数组转换为向量作为向量定义的一部分的方式:
std::vector<int> v(num1, num1+4);
这就是将数组转换为向量而不是作为向量定义的一部分的方式:
std::vector<int> v;
v.assign(num1, num1+4);
或者你的意思是"将我的程序转换为使用向量而不是数组":
std::vector<int> num1 = { 2, 4, 1, 8};
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何在C++中将数组转换为矢量指针
- 将矢量<T>转换为矢量<数组<T>>
- JSON转换为nlohmann JSON-lib中的结构数组
- 将C++中的数组转换为字符串
- NLOHMANN 的 JSON 库将数组转换为结构向量
- 将 int 数组转换为 std::vector<int*>
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- 将链表转换为指针数组时出错
- 无法在 Arduino 中uint8_t数组转换为无符号长整型数组
- 将字节数组转换为带有字节序问题的指针
- 使用 stbi_write_png,如何将 0 和 1 的矩形字节数组转换为单色 png 文件?
- 将浮点数转换为无符号字符数组并打印出来
- 创建一个函数来转换数组元素的类型并返回数组的地址
- 在 c++ 中动态强制转换 ** 数组
- 返回并强制转换数组指针(错误:数组下标的类型..无效)
- 用于递归模板求值的强制转换数组类型
- node.js中使用node-gyp的转换数组
- 如何转换数组中的参数列表