Error in the code

why there is a compilation error ?

helo @prerak_semwal
check now->

@aman212yadav

what there’s no output

reserve dont change size, ur vector size is still 0.\

use resize in place of reserve ,or use pushback for insertion

@aman212yadav

is this the efficient way of storing integer inputs in vector (using reserve to counter the size doubling issue while using push_back)

yes…
u an directly an n size vector and then read input like u do in array.

vector<int> v(n);
for(int i=0;i<n;i++)
   cin>>v[i];
```this  is also efficient
1 Like

@aman212yadav

ok…I wasn’t aware of this method…thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.