Access Violation Mystery with gethostbyname?
<pre><code>std::cout &lt;&lt; WebClient().Load(in.substr(2, in.length()));
</code></pre>

<p>I made a WebClient for fun, and you can pass in a string through cin to in via std::getline(cin, in);  </p>

<p>The starting part of my Load method:</p>

<pre><code>std::string Load(std::string url)
{
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2,2), &amp;wsaData) != 0) {
        return "WSAStartup failed.\n";
    }
    SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    struct hostent *host;
    host = gethostbyname(url.c_str());
    SOCKADDR_IN SockAddr;
    SockAddr.sin_port=htons(80);
    SockAddr.sin_family=AF_INET;
    if(host != nullptr)
    {
        SockAddr.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr);
    }
</code></pre>

<p>I would get an Access Violation because host becomes a nullptr (hence checking it), yet with the same string but passed in differently: WebClient().Load("www.google.ca") it works. and I tried putting c_str() at the end of the substr'ed string with no avail.</p>

<p>I am still learning the quirks, what's up with this? I am using standard libraries from </p>

<pre><code>#include &lt;http.h&gt;
#include &lt;string&gt;
#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#pragma comment(lib,"ws2_32.lib")
</code></pre>
