《C++ Primer》第三章3.5.3节练习“比较数组”
#include <iostream>using namespace std;
bool compare(int* aBegin, int* aEnd, int* bBegin, int* bEnd) {
if ((aEnd - aBegin) != (bEnd - bBegin))
return false;
else {
for ( ; (aBegin != aEnd) && (bBegin != bEnd); aBegin++, bBegin++) {
if (*aBegin != *bBegin) {
return false;
}
}
}
return true;
}
int main() {
int arr1 = { 0, 1, 2,3,4 };
int arr2 = { 0, 1, 2 ,3,4};
if (compare(begin(arr1), end(arr1), begin(arr2), end(arr2)))
cout << "The two arrays are equal." << endl;
else
cout << "The two arrays are not equal." << endl; //缺少了
return 0;
} 谢谢分享 正常的啊 代码能跑
页:
[1]