Stepping through your program, i noticed you resize vecOfNums, then you
push_back
values onto it.
resize
actually adds elements into the vector in this case. You should instead be using
reserve
to reserve space instead. But this is not needed because vector dynamically allocates memory for you.
http://www.cplusplus.com/reference/vector/vector/resize/
http://www.cplusplus.com/reference/vector/vector/reserve/
Your next problem is lines 41 to 44:
1 2 3 4 5
|
vector<int> numsVec;
while (cin >> nums)
{
numsVec.push_back(nums);
}
|
This is an infinite loop. There are many ways around this problem, here are two:
1 2 3 4 5 6 7 8
|
while (true) //infinite loop
{
cin >> nums;
if(nums == 0){
break;//break out of loop
}
numsVec.push_back(nums);
}
|
1 2 3 4 5 6
|
cin >> nums;
while (nums != 0)
{
numsVec.push_back(nums);
cin >> nums;
}
|
And a minor problem with your code:
you do not need the following lines because they are not used:
1 2 3
|
#include <array>
#include <algorithm>
#include <sstream>
|
There is one problem in your function. you are using
i
in both your for loops, you need to pick another variable name to use for either your inner or outer loop.
Other then that, you could remove
vector<int> store;
and replace it with
vec[i]
, but this is not needed.