Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving array contents to file using Visual Studio immediate window

I am using Visual Studio 2017 and C++ to debug a huge project

I don't use it frequently so I am not sure if this is possible or not, but is there any way to save all the contents of an array to a file using the immediate window? I have been looking around to find out the capabilities of the immediate window but there doesn't seem to be any place where this is clearly explained

This page comes up on google which only says it's possible to display contents of a variable, but doesn't give much more information

By looking around stackexchange I have found that a range of values in an array can be displayed using something like

array_name, 10  

which will show the first 10 elements of an array, and this answer says there is a way to simply direct the output in the immediate window to a file, but my array has thousands of elements, and the array_name, XX trick only displays first 100 elements on the array in the immediate window

Is there a straightforward way to save contents of a variable or array to file in Visual Studio 2017 while the program is at a breakpoint?

like image 860
user13267 Avatar asked Mar 08 '26 17:03

user13267


1 Answers

You can get the content of any variable by copying it out of the watch window. From there you can pasted it into a file. I don't think there's anything to write it to a file from VS. You could of course have your program do that.

To get the variable values to the clipboard add a watch expression for your variable in the watch window (it's along the bottom of VS). However, don't just copy the expression (as that will get capped) expand it out then select all (Ctrl+A) and then right click Copy Value and you should get it to the clipboard. Depending on the contents of your array there might be truncation. enter image description here

like image 96
Andy Sterland Avatar answered Mar 11 '26 07:03

Andy Sterland