Converting a void* to a std::string

后端 未结 4 2030
深忆病人
深忆病人 2020-12-29 20:32

After perusing the web and messing around myself, I can\'t seem to convert a void*\'s target (which is a string) to a std::string. I\'ve tried using sprintf(buffer, \"

4条回答
  •  梦毁少年i
    2020-12-29 20:58

    If you trying to format the address as text you can use a stringstream:

    std::stringstream strm;
    strm << ptr;
    std::string str = strm.str(); 
    
    // str will now have something like "0x80004567"
    

    If that's not what you are interested in, please clarify your question.

提交回复
热议问题