필터 지우기
필터 지우기

How to send vector of string to MATLAB compiled DLLs, using mwArray?

조회 수: 1 (최근 30일)
Abhay Prakash
Abhay Prakash 2016년 2월 26일
답변: Guillaume 2016년 2월 26일
Page at mwArray class describes about constructor to create a mwArray cell of array of string as: mwArray(mwSize num_strings, const char** str).
I have a vector of string which has been dynamically populated. I have converted vector<string> to char** and trying to make mwArray with this data. However, the constructor signature has const char**, so it is failing to convert char** to const char**
How else a vector of string can be set to a mwArray cell and sent to MATLAB DLLs?

채택된 답변

Guillaume
Guillaume 2016년 2월 26일
Yes, C++ will not let you convert T** to const T**. While you probably could use an explicit cast, the best solution is to change your conversion from vector<string> so that it outputs directly const char**.
You must actually have purposefully cast away the constness of const char* returned by string.c_str, so don't do that!
std::vector<std::string> strings { "one", "two", "three"};
std::vector<const char*> cstrings;
for (size_t i = 0; i < strings.size(); ++i)
cstrings.push_back(strings[i].c_str()); \\convert string to const char*
mwArray mstrings(cstrings.size(), cstrings.data()); \\cstrings.data() is const char**

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by