Hi,

I current I have a vector <void*> that I need to populate with values, stored as char*. Is there a way to convert to void*, then back to char* whenever needed?

I have tried casting and using static/reinterpret_cast but when I try to output (converting from void* back to char* that is), I get a null value - unfortunately I can't change the vector to vector<char*> or anything, I have to use it as it is :(

Any help would be much appreciated, thanks :)

Recommended Answers

#include <iostream>
 
int main()
{
char* p = "eggs on toast";
void* q = (void*) p; // to void*...
char* r = (char*) q; // and back
 
std::cout << r;
return 0;
}
Jump to Post

All 2 Replies

#include <iostream>
 
int main()
{
char* p = "eggs on toast";
void* q = (void*) p; // to void*...
char* r = (char*) q; // and back
 
std::cout << r;
return 0;
}

Ah yes, didn't know you could do it that way thanks!

Turned out it was always returning null because nothing was getting put into the vector for some reason, but got it working now thankfully :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.