快捷方式比较C++

发布于 2025-01-25 07:29:48 字数 340 浏览 2 评论 0原文

考虑在堆上分配的两个数据阵列:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2025-02-01 07:29:48

由于您正在提及memcpy,因此也有 memcmp
这似乎是您所追求的?

另请参见比较快速的两个内存区域

Since you're mentioning memcpy, there's also memcmp.
This seems to be what you're after?

See also Compare fast two memory regions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文