I am trying to initialise a vector as follows:
vector<int> vect(n, 2);
This statement initialises vect
to contain n
elements of type int
with value 2
. n
is a variable of type size_t
that has been checked to ensure n <= vect.max_size()
is always true.
I am currently testing my code so far on Code::Blocks. It works for any arbitrary small value of n
, but when I try to run it in the IDE at n = vect.max_size()
, the program terminates, saying an unknown application error occurred, and to speak to the developer (me).
Does anyone know what is wrong? Is this not the right way to initialise the vector to the maximum size possible in runtime? I checked, my math is correct, n
didn't exceed vect.max_size()