0

将 int 数组转换为向量的最简单方法是什么?并将其与 if 语句一起使用。

IE

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)。

谢谢,

4

1 回答 1

7

这是将数组转换为向量作为向量定义的一部分的方式:

std::vector<int> v(num1, num1+4);

这是将数组转换为向量的方式,而不是向量定义的一部分:

std::vector<int> v;
v.assign(num1, num1+4);

或者您的意思是“将我的程序转换为使用向量而不是数组”:

std::vector<int> num1 = { 2, 4, 1, 8};
于 2013-10-19T03:12:22.073 回答