Creating a Bitcoin address using the 9 steps. Stuck on stage 2
The problem is that you are hashing the string of hex characters instead of the actual bytes that the hex string represents. You should be using an array instead with the bytes specified. The following should work:

string sha256(char[] str, size_t len)
{
  unsigned char hash[SHA256_DIGEST_LENGTH];
  SHA256_CTX sha256;
  SHA256_Init(&amp;sha256);
  SHA256_Update(&amp;sha256, str, len);
  SHA256_Final(hash, &amp;sha256);
  stringstream ss;

  for(int i = 0; i &lt; SHA256_DIGEST_LENGTH; i++)
  {
    ss &lt;&lt; hex &lt;&lt; setw(2) &lt;&lt; setfill('0') &lt;&lt; (int)hash[i];
  }
return ss.str();
}

int main()
{
  char[] arr = {0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, 0x88, 0x7e, 0x5b, 0x23, 0x52};
  cout &lt;&lt; endl;
  cout &lt;&lt; sha256(arr, 32) &lt;&lt; endl;
  return 0;
}