Hi am having problems understanding the difference between
a.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <algorithm>
usingnamespace std;
int main()
{
constchar p[]="hello",p1[]="hello";
cout<<((equal(begin(p),end(p),begin(p1)))?" equal" :" not equal");
return 0;
}
b.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <algorithm>
usingnamespace std;
int main()
{
constchar *p="hello",*p1="hello";
cout<<((equal(begin(p),end(p),begin(p1)))?" equal":" not equal");
return 0;
}
# problems are
1. i thought arrays can be explictly converted to pointers to their first
element and i am getting an error on the second example.
2. i understand that the generic equal function above uses the element type
operators to compare if elements are equal? but do c_style strings constchar p[]="hello",p1[]="hello"; really have == operator
or aren't this c_style strings?? this is because the first example is
working fine so i dont get where it gets == on const char* or does it use
strcmp()? or does it compare each element as a char using == ?