Onome Sotu
Onome Sotu

Reputation: 676

What is the standard way of initializing a boolean vector in C++

I have researched around but haven't found any clear answer.

How do I initialize a boolean vector of a particular size all set to either true or false?

Upvotes: 1

Views: 5038

Answers (1)

tasosxak
tasosxak

Reputation: 109

This will uniformly initialize the vector:

const size_t SIZE = 10; // However many elements you want in the vector.
const bool initial_value = false; // All elements will be set to this value
std::vector<bool> m_allFalse(SIZE, initial_value);

General, to initialize boolean values at the beginning, you can use this:

bool temp[] = { true, false, false, true };
std::vector<bool> variousBool ( temp, temp + sizeof(tempBool) / sizeof(bool) );

Upvotes: 2

Related Questions