Convert char* to uint8_t

后端 未结 4 956
借酒劲吻你
借酒劲吻你 2020-12-18 02:09

I transfer message trough a CAN protocol.

To do so, the CAN message needs data of uint8_t type. So I need to convert my char* to ui

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 03:04

    More safe example in C++ way

    char* bufferSlidePressure = "123";
    std::string buffer(bufferSlidePressure);
    std::stringstream stream;
    
    stream << str;
    int n = 0;
    
    // convert to int
    if (!(stream >> n)){
        //could not convert
    }
    

    Also, if boost is availabe

    int n = boost::lexical_cast( str )
    

提交回复
热议问题