我的 bool 数组有一个非常奇怪的问题。我有 3D boolean 数组:
bool tab[wordLength][wordLength][nl];
我用 0 填充它,这些是我稍后对该数组执行的唯一操作(在几个 for 循环中):
(...)
tab[1][s][v] = true;
和
(...)
if(tab[p-1][s-1][b] == true && tab[l-p-1][s+p-1][c] == true){
tab[l-1][s-1][a] = true;
}
问题是,当我想在某些单元格中写入该数组的内容时,我得到 1 或 0(应该是),但在某些单元格中,我得到的数字是整数,例如 182 - 这怎么可能bool 数组,我只能让它为真或为假?
最佳答案
试试这个,或者你可以按照 sailfish009 的建议使用 memset,
bool tab[wordLength][wordLength][nl] = {{{0}}};
关于C++ bool 数组返回 1 或 0 以外的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43343343/