[Solved] Passing std::string as parameter gives error – htons function

[ad_1]

You need to convert your std::string to a std::uint16_t. I’d recommend a stringstream

std::istringstream ss(string); // maybe pick a different name
std::uint16_t port{};
ss >> port;
address.sin_port = htons(port);

Be sure to #include <sstream>

2

[ad_2]

solved Passing std::string as parameter gives error – htons function