快捷方式比较C++
考虑在堆上分配的两个数据阵列:
int *A = new int[5];
int *B = new int[5];
// Some code which changes data pointed to by A and B
现在我想比较这两个阵列(不是指针,而是数据A和B点)。也就是说,我想检查数组的元素是否相等。
有人可能会建议元素与循环进行比较,但是由于有诸如memcpy
之类的功能,允许避免通过数据复制循环,因此假设有一个类似的功能可以避免通过阵列循环以进行元素的比较。
C ++
对此有任何快捷方式吗?
Consider two arrays of data allocated on the heap:
int *A = new int[5];
int *B = new int[5];
// Some code which changes data pointed to by A and B
Now I want to compare these two arrays (not the pointers, but the data A and B point at). That is, I want to check out if the elements of the arrays are equal.
One might suggest elementwise comparison with a loop, but since there are functions such as memcpy
which allow to avoid looping through data to copy it, it seems reasonable to assume there is a similar function which would allow to avoid looping through an array for elementwise comparison.
Does C++
have any shortcuts for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您正在提及
memcpy
,因此也有memcmp
。这似乎是您所追求的?
另请参见比较快速的两个内存区域。
Since you're mentioning
memcpy
, there's alsomemcmp
.This seems to be what you're after?
See also Compare fast two memory regions.