Using the C++ Math Library | ![]() ![]() |
ToString( )
To extract a string from an mwArray
, you can use the mwArray
member function ToString()
. For example,
mwArray A = "MATLAB"; mwString s = A.ToString(); char *c = strdup((char *)s);
The mwString
class contains a dynamically allocated string and handles its memory management, including freeing the string when the mwString
object goes out of scope. The mwString
class has a cast operator that converts it to a char *
.
You can safely use ToString()
to construct char *
function arguments, for example, strcat(str, A.ToString())
. If you need to refer to the string in a context beyond the scope of the mwString
object, use strdup()
to make a copy of the string for yourself. Don't forget to free the copy when you're done with it.
Note
Casting an mwString to a char * does not make a copy of the string. This pointer will be freed when the mwString itself goes out of scope. Do not free it yourself. |
![]() | ExtractScalar( ) and ExtractData( ) | Library Routines | ![]() |