title: Split URL into Host, Port and Resource - C++
body: <p>I need to split the URL into host, port and resource. I searched a lot of references but couldn't find anything that could help me. This is how I want:</p>
  
  <p>eg:
  url is - 1.2.3.4:5678/path1/path2.html
  Necessary output is: Host - 1.2.3.4, Port - 5678, Resource - /path1/path2.html</p>
  
  <p>This is how I tired:</p>
  
  <pre><code>#include &lt;iostream&gt;
   #include &lt;cstddef&gt;
   #include &lt;string&gt;
   using namespace std;
  
  int main()
  {
     string url="http://qwert.mjgug.ouhnbg:5678/path1/path2.html";
     size_t found = url.find_first_of("://");
     cout&lt;&lt;found&lt;&lt;endl;
     string protocol=url.substr(0,found);
     size_t found1 =url.find_first_of(":");
     cout&lt;&lt;found1&lt;&lt;endl;
     string host =url.substr(found+3,found1-found+1);
     size_t found2 = url.find_first_of(":/");
     string port1 =url.substr(found1+7,found2+found1-1);
     string port =url.substr(found2+1);
     cout&lt;&lt;protocol&lt;&lt;endl;
     cout&lt;&lt;host&lt;&lt;endl;
     cout&lt;&lt;port1&lt;&lt;endl;
     cout&lt;&lt;port;
     return 0;
  }
  </code></pre>
  
  <p>My expected result is:</p>
  
  <pre><code>Protocol - http
  Host - qwert.mjgug.ouhnbg
  Port - 5678
  Resource - path1/path2.html
  </code></pre>
  
  <p>But my result is:</p>
  
  <pre><code>http:                                                                                                                                                  
  qwert.mj                                                                                                                                               
  t.mjgug                                                                                                                                                
  //qwert.mjgug.ouhnbg:5678/path1/path2.html
  </code></pre>
  
  <p>What should I change?</p>