Using the C++ Math Library | ![]() ![]() |
Providing Your Own Print Handler
By default, the library sends output to the C++ standard output stream, cout
. However, instead of sending output directly to the standard output stream, the MATLAB C++ Math Library calls a print handler when it needs to display an error message or warning. The print handler used by the library takes a single argument, a const char *
(the message to be displayed), and returns void
.
static void DefaultPrintHandler(const char *
s)
{
cout << s;
}
If you want to perform a different style of output, you can write your own print handler and register it with the MATLAB C++ Math Library. Any print handler that you write must match the signature of the default print handler: a single const char *
argument and a void
return.
To register your function and change which print handler is used, you must call the routine mwSetPrintHandler
. mwSetPrintHandler
takes a single argument, a pointer to a function that displays the character string, and returns void
.
void mwSetPrintHandler(mwOutputFunc f);
![]() | Printing, Exceptions, and Memory Management | Using the Print Handler to Print Your Own Messages | ![]() |