my entry-point codegen function:
function out = useImageAndString(imagePathstr)
imagePathstr (1,1) string = "./input.txt"
assert(isstring(imagePathstr));
assert(numel(imagePathstr)==1);
coder.cinclude('test1.h');
coder.updateBuildInfo('addSourceFiles', 'test1.cpp');
imgPath = char(imagePathstr);
coder.ceval('myFunction',coder.rref(imgPath));
Generate C++ code for the above function in command line:
t.VariableStringLength = true;
codegen -config:mex useImageAndString -args {t} -launchreport -lang:c++
I can generate C++ code successfully, but the first parameter "imagePathstr" passed to my C++ occasionally results(const char* imagePathstr) in a garbled last character. So how can I fix it?
test1.cpp:
void myFunction(const char* imagePathstr)
std::string dbFile(imagePathstr);
std::cout << "database name:" << dbFile << std::endl;// The last character is garbled ???
RUN in R2022b