Cómo parsear el host desde una URL en C++ usando Boost::URL

Si tienes una URL como:

snippet.cpp
std::string myURL = "https://subdomain.example.com/api/test";

puedes parsear el hostname desde ella usando Boost::URL (necesitas al menos Boost 1.81.0, las versiones anteriores de boost no tienen Boost.URL) usando

snippet2.cpp
boost::urls::url_view url(myURL);
std::string host = url.host();

std::cout << host << std::endl; // Prints "subdomain.example.com"

Ejemplo completo:

urlhost.cpp
#include <string>
#include <iostream>

#include <boost/url.hpp>

int main() {
    std::string myURL = "https://subdomain.example.com/api/test";

    boost::urls::url_view url(myURL);
    std::string host = url.host();

    std::cout << host << std::endl; // Prints "subdomain.example.com"
}

Compila usando

build_urlhost.sh
g++ -o urlhost urlhost.cpp -lboost_url

Echa un vistazo a artículos similares por categoría: Boost C/C++