我已经初始化了一个vector
,bools
但由于某种原因,一切都设置为false
。为什么我不能设置 a vector
of
bool
to true
?
#include <iostream>
#include <vector>
int main()
{
std::vector<bool> d_WFlag;
int d_numGrids = 4;
d_WFlag.resize(d_numGrids);
d_WFlag[0] = false;
std::cout << std::noboolalpha << d_WFlag[0] << " == " << std::boolalpha << d_WFlag[0] << std::endl;
for(int i = 1; i < (d_numGrids - 1); ++i)
{
d_WFlag.push_back(true);
std::cout << std::noboolalpha << d_WFlag[i] << " == " << std::boolalpha << d_WFlag[i] << std::endl;
}
d_WFlag[d_numGrids - 1] = false;
std::cout << std::noboolalpha << d_WFlag[d_numGrids - 1] << " == " << std::boolalpha << d_WFlag[d_numGrids - 1] << std::endl;
return 0;
}