Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method to automatically view vector element in watch window in VS 2010

Is there any technique that would let one put a vector element in a watch window, and actually see it update when it changes?

This is the context.

vector<int> x;
x.push_back(3);

Then put x[0] into the watch window and actually see its value.

Failing a solution to that issue, what is the best alternative?

like image 309
EvilTeach Avatar asked Apr 28 '11 16:04

EvilTeach


2 Answers

Add x to a watch window. VS should display its elements. Click on the plus link to the left to see its elements each in its own row. Click on the name of the element (i.e. x[0]) and drag it into its own blank row in the watch window. That should give you a new row watching the element you wanted. Make sure what you click on for dragging is the variable name and not its value (dragging the value will watch the value).

like image 182
Pablo Avatar answered Nov 16 '22 16:11

Pablo


Pablo's method works for only fixed index values. If you want to set the index using a variable use:

((x)._Myfirst)[index]

It is ugly and hard to remember but does the trick.

like image 3
nimcap Avatar answered Nov 16 '22 18:11

nimcap