Thanks for your reply. I found the answer to the problem. In brief is in using reserve() and then access with [] whould work for such types like int and double. But it is an inconsistent use of it because even entering numbers in the way vec[i], a simple check to the size of the element vec.size() after the elements has been entered will return 0. That is why is inconsistent, so it should be avoided.

On considering the above, I would like to know an alternative method which is efficient to do the same.