Vectors in c++ are dynamically sized.
You can create a vector without a size argument in the constructor then push size number of elements like so:
vector<int> makeGaps (int size){
vector<int> vectorOfGaps;
for(int i = 0; i < size;i++){
vectorOfGaps.push_back(i);
}
return vectorOfGaps;
}
Edit: Also, as someone already pointed out in your comments, it appears you had an off by one error in your for loop. If the for loop runs until x <= size
, it will iterate size+1
number of times.
solved C++ program does nothing when executed