我正在尝试逐个元素地比较两个 int 数组以检查是否相等。我似乎无法让它工作。也欢迎基本指针资源。谢谢!
int *ints;
ints = new int[10];
bool arrayEqual(const Object& obj)
{
bool eql = true;
for(int i=0; i<10; ++i)
{
if(*ints[i] != obj.ints[i])
eql = false;
}
return eql;
}
最佳答案
接下来呢?
#inlcude <algorithm> bool arrayEqual(const Object& obj) { return std::equal(ints,ints + 10, obj.ints); }
注意:equal 函数要求两个数组的大小相等。
关于c++ - 垒球 C++ 问题 : How to compare two arrays for equality?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1516574/