在C++中初始化布尔向量的标准方法是什么

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

本文关键字:标准 方法 是什么 向量 布尔 C++ 初始化      更新时间:2023-10-16

我四处研究,但没有找到任何明确的答案。

如何初始化特定大小的布尔向量,全部设置为 true 或 false?

这将统一初始化向量:

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);

常规要在开始时初始化布尔值,您可以使用以下内容:

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