If you need a function that can handle both pointers and STL iterators, look at std::equal in <algorithm> .
I believe that std::equal is C ++ - a way to execute std::memcmp (which is really C ++, but std::memcmp does not handle iterator objects).
#include <iostream> #include <vector> #include <algorithm> int main (int argc, char *argv[]) { int a1[] = {1,2,3,4}; int a2[] = {1,9,3,5}; int * p1 = new int[4]; std::vector<int> vec (a2, a2+4); *(p1++) = 1; *(p1++) = 2; *(p1++) = 3; *(p1++) = 4; p1 -= 4; if (std::equal (a1, a1+4, p1)) { std::cout << "memory of p1 == memory of a1\n"; } if (std::equal (vec.begin (), vec.end (), p1) == false) { std::cout << "memory of p1 != memory of vec\n"; } }
Exit
memory of p1 == memory of a1 memory of p1 != memory of vec
source share