Consider the following code piece:
... int N,var; vector nums; cin >> N; while (N--) { cin >> var; nums.push_back(var); } ... >
vector nums(N); for (int i = 0; i < N; i++) { cin >> nums[i]; }
In the general case, this is actually more efficient. Calling std::vector::push_back() repeatedly without an initial reserve will lead to lots of reallocations.
std::vector::push_back()
reserve