0
fill_n not working
Hi Please refer code below: I have at the end of code added fill_n code lines but vector is not getting updated... Please suggest. Do I need to do push_back all the time and fill_n does not work this way? https://code.sololearn.com/cd3ezhtwAqKI/?ref=app
3 Answers
0
What you really want is instead of using reserve(), you should use resize().
Reserve: https://cplusplus.com/reference/vector/vector/reserve/
Resize: https://cplusplus.com/reference/vector/vector/resize/
+ 1
Yes, the reserve() does only change the max value of size, so the size doesn't change, if you try to fill_n more than the size it will not change the vector.
0
Thanks TomĂĄs Ribeiro
It works as per my need with reset
I dont have to use fill_n also
Now my work is done but curious to know that whats the use of fill_n ? Does it work only on available elements and it cant add new elements alltogether ?
https://code.sololearn.com/cN0xHypY26lT/?ref=app