#include <iostream>
#include <vector>
#include <stdexcept> 

std::vector<int> testVector;

void SetVector(int position, int value) {
   try
    {
       testVector.at(position) = value;
    }
   catch (const std::out_of_range& oor) {
      testVector.reserve(position);
      testVector[position] = value;
   }
}

int main()
{
    std::cout << testVector.capacity() << std::endl;
    SetVector(1, 1);
    std::cout << testVector[1] << std::endl;
    SetVector(1, 2);
    std::cout << testVector[1] << std::endl;
}