title: Passing std::string as parameter gives error - htons function
body: <p>I'm working with sockets, but when I compile my program I get some errors.</p>
  
  <p>This is my code:</p>
  
  <pre><code>address.sin_family = AF_INET;
  address.sin_port = htons(string); // here I get an error
  inet_aton(str.c_str(),&amp;address.sin_addr);
  </code></pre>
  
  <p>What I get is:</p>
  
  <blockquote>
    <p>cannot convert ‘__gnu_cxx::__alloc_traits > >::value_type {aka std::__cxx11::basic_string}’ to ‘uint16_t {aka short unsigned int}’ for argument ‘1’ to ‘uint16_t htons(uint16_t)’</p>
  </blockquote>
  
  <p>How can I solve this error?</p>
  
  <p>Thanks in advance.</p>