Question: I am working in a mqtt application and when i receive the information of the payload from the mqtt broker and try to convert it from the void\* that is message->payload to an int as 

```
signed int var_1=*((int*) message->payload);

```

instead of converting it to the number it is converting it to another one, to see this I am using the following code:

```
printf("Message:%s\n",message->payload);
printf("Message:%i\n",var_1);

```

Which shows:

```
Message:-58
Message:3683629

```

I also thought about the payload being a string, but if I use the stoi function it gives me the error:

```
can not convert from ´void*´ to ´int´ with stoi function.

```

Answer: 
In C++ you can't automatically convert from `const void*` to `const char*`.

You need an explicit static cast:

```
int i=atoi(static_cast<const char*>(message->payload));

```

Notice I've used `atoi()` which is a C library function (`#include <cstdlib>`).

There's little point converting it to a `std::string` just to parse that to an `int`.

All this assumes you're correct to think the payload is a character encoded decimal integer in a c-style string.
I didn't quite understand if message->payload holds the number itself or a string representation for it.
If message->payload holds the **memory location** in which the number is stored, so var\_1 holds the **value**.
Therefore, you cannot expect those values to be the same.
Regarding stoi - it receives a string that hold number, but as a string. For example - 

```
std::string num = "1234";
int convertedNumber = stoi(num);

```