Converting a void* to a std::string

后端 未结 4 2035
深忆病人
深忆病人 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条回答
  •  悲哀的现实
    2020-12-29 20:57

    If the void is a const char*, then you can just call the std::string constructor with it, i.e.

    const char* cakes = something;
    std::string lols = std::string(cakes);
    

提交回复
热议问题