c++提取ip和端口

#include <iostream>

int main()
{
    std::string str = "192.168.9:8086";
    std::string buffer1;
    buffer1.resize(128);

    int port = 0;
    sscanf(str.c_str(), "%[^:]:%d", &buffer1[0],&port);

    //std::string str = "https://192.168.9:8086/test";
    //std::string buffer1;
    //buffer1.resize(128);

    //int port = 0;
    //sscanf(str.c_str(), "https://%[^:]:%d", &buffer1[0], &port);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章