Do C++ STL functions work in S-function code?

4 views (last 30 days)
I tried to print to stdout using std::cout << myMessage << std::endl, but the message does not appear, either in the console or the terminal from which I launched MATLAB, whereas printf works as expected. Why does std::cout not work?
Background:
  • I created a minimal model, threeModel.slx, containing an S-Function block, in local directory working.
  • I copied matlab/2016b/toolbox/simulink/simdemos/simfeatures/src/timestwo.c as working/three.cpp.
  • I #include d iostream and cstdio into three.cpp .
  • I inserted the following code into three.cpp at the end of function mdlOutputs: std::cout << "Testing cout." << std::endl; printf("Testing printf."):
  • I compiled with MEX: >> mex three.cpp (Built normally.)
  • I set the S-Function block's S-Function name parameter to three and left the other parameters with default settings (empty).
When I ran simulation (^T), I saw "Testing printf" (repeatedly) in the console window from which I had launched MATLAB, but no "Testing cout." Why not? Thanks!

Answers (1)

Amittai Aviram
Amittai Aviram on 17 Jan 2017
I have discovered that output to std::cout gets routed to the Diagnostic Viewer: if I click on "View diagnostics" at the bottom of the model window, I can see it. Now my question is how to route the output elsewhere, e.g., to the MATLAB console.

Products

Community Treasure Hunt

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

Start Hunting!