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, \"
Based on your comment "What I meant was to convert what the void* is pointing to (which is a string) into a string."
Assuming you have this:
std::string str = ...;
void *ptr = &str;
You can just cast back to the string:
std::string *pstr = static_cast(ptr);
Note that it is on you to verify that ptr
actually points to a std::string
. If you are mistaken and it points to something else, this will cause undefined behavior.