C++ converting a mac id string into an array of uint8_t

前端 未结 4 1018
小蘑菇
小蘑菇 2021-01-15 17:42

I want to read a mac id from command line and convert it to an array of uint8_t values to use it in a struct. I can not get it to work. I have a vector of stri

4条回答
  •  深忆病人
    2021-01-15 18:22

    I think you are using the std::hex in the wrong place:

    #include 
    #include 
    
    int main()
    {
        std::string     h("a5");
        std::stringstream   s(h);
        int x;
    
        s >> std::hex >> x;
        std::cout << "X(" << x << ")\n";
    }
    

提交回复
热议问题