You are returning pointer to a local array which is not required to live beyond the function.
You need to make the buffer persist beyond the scope of the function by allocating it dynamically using malloc
. And ofcourse remember to free
it later.
Oh just noticed its C++.
So drop the idea of malloc
and free
simply use std::string
and not char *
.