As others said, you should wrap the functions in a copy, and then return from the C-style buffer. This solution using a short life wrapper object makes it pretty elegant:
using namespace std; class Wrap { public: Wrap(string &S,int Length):Buffer(Length),Orig(S) {
This code outputs:
Construct Function Destruct HQQa
which demonstrates how and what it works. This does not solve the problem, which should indicate the length of the buffer, but it allows a function called to change the length and contents of the string (up to the specified buffer size).
source share