Convert char* to uint8_t

后端 未结 4 709
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 02:30

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 02:57

    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 )
    

提交回复
热议问题