0

what would be the simplest way to convert int array to vector? and use it with if statement.

i.e.

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 is declared as a function prototype (BOOL).

thanks,

2
  • Please define testNUM Commented Oct 19, 2013 at 3:12
  • num1 and num2 are both arrays, why would you need to convert them to vectors? Commented Oct 19, 2013 at 3:13

1 Answer 1

8

This is how one converts an array to a vector as part of the vector definition:

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

This is how one converts an array to a vector not as part of the vector definition:

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

Or perhaps you meant "convert my program to use vectors instead of arrays":

std::vector<int> num1 = { 2, 4, 1, 8};
Sign up to request clarification or add additional context in comments.

1 Comment

'bool testNUM(int set1[], int set2[], int size);'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.