作为C ++的新手,为什么evaluate()
在循环后不显示值?注意:我们正在遍历长度为5的自创建数组。
int i
这在控制台上返回:
int i = 0;
std::cout << i << "\n" // for testing: prints 0
for (CArray<int>::Iter it(arr); it; ++it)
{
if (*it != eq[i])
return 1;
++i
std::cout << i << "\n"; // for testing: prints 1, 2, 3, 4, 5
}
std::cout << i << "\n"; // why does this not print anything?
答案 0 :(得分:2)
int i = 0;
std::cout << i << "\n" // for testing: prints 0
for (CArray<int>::Iter it(arr); it; ++it)
{
if (*it != eq[i]) {
std::cout << "error" << "\n";
return 1;
}
++i
std::cout << i << "\n"; // for testing: prints 1, 2, 3, 4, 5
}
std::cout << i << "\n"; // why does this not print anything?
这在控制台上返回:
0
1
2
3
4
5
error
所以,问题出在循环而不是变量。