遍历多维数组? [英] Loop through a multidimensional array?
本文介绍了遍历多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何遍历多维数组?假设我们有这样的事情:
How would I loop through a multidimensional array? Say we had something like this:
class blah
{
public:
blah();
bool foo;
};
blah::blah()
{
foo = true;
}
blah testArray[1][2];
testArray[1][0].foo = false;
我将如何遍历 testArray
找出 foo
中的哪一个是假的?
How would I go about looping through testArray
to find which one of foo
is false?
推荐答案
class blah
{
public:
blah();
bool foo;
};
blah::blah()
{
foo = true;
}
int testArrayFirstLength = 1;
int testArraySecondLength = 2;
blah testArray[testArrayFirstLength][testArraySecondLength];
testArray[1][0].foo = false;
for (int i = 0; i < testArrayFirstLength; i++) {
for (int j = 0; j < testArraySecondLength; j++) {
if (!testArray[i][j]) {
blah thing = testArray[i][j]
}
}
}
那好吗?还是您在寻找其他东西?
That good? Or were you looking for something else?
这篇关于遍历多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文