if (iar1 == iar2)
Here iar1
and iar2
are decaying to pointers to the first elements of the respective arrays. Since they are two distinct arrays, the pointer values are, of course, different and your comparison tests not equal.
To do an element-wise comparison, you must either write a loop; or use std::array
instead
std::array<int, 5> iar1 {1,2,3,4,5};
std::array<int, 5> iar2 {1,2,3,4,5};
if( iar1 == iar2 ) {
// arrays contents are the same
} else {
// not the same
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…