0

I have found this question a few times, but none of them seem to offer a good answer (please mark as duplicate if I missed it).

I have a method that returns a std::vector<unsigned short>, but I want to allow for more numbers than an unsigned short can hold, so I would like to convert it to a std::vector<int> before I add my bigger numbers to it.

So I want to convert it while keeping the data & order intact. A std::vector<unsigned short> that contains [1, 2, 3] should contain [1, 2, 3] after it has been converted to std::vector<int>.

vrwim
  • 13,020
  • 13
  • 63
  • 118

1 Answers1

4

Just construct the std::vector<int> from the std::vector<unsigned short>:

std::vector<unsigned short> org_vec;

// ...

std::vector<int> int_vec(std::begin(org_vec), std::end(org_vec));
Paul Evans
  • 27,315
  • 3
  • 37
  • 54