Using p->a would only let you access public variables of A. Since a is a protected variable, you should use cout << a, since a is inherited in class B.
I think you could use cout << p->a by friending class B.
Or by using a pointer to B instead of a pointer to A, as JonJon noted.