I was looking for a way to stuff some data into a string across a DLL boundary. Because we use different compilers, all our dll interfaces are simple char*.
Is ther
Considering Patrick's comment I would say, it's OK and convenient/efficient to directly write into a std::string. I would use &s.front()
to get a char *
, like in this mex example:
#include "mex.h"
#include
void mexFunction(
int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[]
)
{
std::string ret;
int len = (int)mxGetN(prhs[0]);
ret.reserve(len+1);
mxGetString(prhs[0],&ret.front(),len+1);
mexPrintf(ret.c_str());
}