I know in C++11 they added the feature to initialize a variable to zero as such
double number = {}; // number = 0
int data{}; // data = 0
Is there a similar way to initialize a std::vector
of a fixed length to all zero's?
I know in C++11 they added the feature to initialize a variable to zero as such
double number = {}; // number = 0
int data{}; // data = 0
Is there a similar way to initialize a std::vector
of a fixed length to all zero's?
You don't need initialization lists for that:
std::vector<int> vector1(length, 0);
std::vector<double> vector2(length, 0.0);
vector(length)
should work?
– Daniel Gratzer
Oct 28 '12 at 15:29
std::vector<int> vec(42);
– avakar Oct 28 '12 at 15:27