Search code examples
c++visual-studiomatlabvisual-studio-debuggingimmediate-window

Truncated String Visual Studio 2022 Immediate Window C++


I'm developing a MATLAB MEX-file (DLL) in C++ that I'm debugging with Visual Studio. I'm able to successfully step through the code but I'm having problems displaying the contents of certain variables (matrices).

Matrices are stored in contiguous blocks of memory float[N] or double[N] where N is a template parameter (N is known at compile time).

I need to control the precision of the formatting of the numbers in the matrices, and I'd also like the elements formatting a particular way (so they can easily be entered back in to MATLAB for comparison) so I wrote a quick printMat function to convert the matrix to a string. I then call this function in the immediate window when I want to inspect the contents of a matrix.

My problem: The immediate window only displays part of the string e.g.

"[ -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08...

This string should actually be.

"[ -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08; -1.0737417600000000e+08, -1.0737417600000000e+08, -1.0737417600000000e+08]"

I can see the entire string if the matrix is smaller but that's just not an option in my case.

What I've tried so far :

  • Printing to std::cout
  • Printing to std::cerr

Unfortunately nothing displays on cout or cerr my guess is they are controlled by the MATLAB process and won't print anything until the debugger "releases" the process.

My question:

Is there a way to get an unadulterated version of this string from the immediate window? I really don't want to litter my code with print statements or temporary debugging string since that will require a rebuild each time I want to inspect the value of a new variable.

Update:

I ultimately ended up writing the the string to a file in the printMat function. I then kept the file opened in Notepad++. After each call to printMat Notepad++ would prompt me to update the contents of the file. I could then copy the text into MATLAB for comparison. It was a little cumbersome but managable.


Solution

  • You can reprot the problem to Developer Community and post link here. This is a compromise: there is a view button on the right. Click it and select text visualizer. Then you can see the string. enter image description here

    enter image description here