Hi Rakesh,
From what I can gather, you are trying to send std::string (UTF-8) from C++ to MATLAB and getting an exception saying, “Input data can only contain ASCII characters”.
Here’s a workaround to send std::string (UTF-8) from C++ to MATLAB:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
std::string utf8String = u8"サンプル文字列"; // Translates to : "Sample String"
// Convert std::string to C-style string
const char *cStr = utf8String.c_str();
plhs[0] = mxCreateString(cStr);
(file name: sendingUTF8.cpp)
After saving sendingUTF8.cpp run the following command in the MATLAB terminal:
(output on successful compilation)
After successfully compiling sendingUTF8.cpp you can run the following command to display the UTF-8 string received from C++:
(string successfully displayed in MATLAB, translates to "Sample String")
I hope this helps, thanks!