An easy way to view a vector item in a debugger

I am using Visual Studio 2013 and in its long history it could never show a vector element in the debugger complaining about the message no operator "[]" matches these operands. I know that there is a workaround that requires input v.operator[](n), but for me this is unacceptable. I want to hover over v[n]and see its value or, at most, select or cut and paste v[n]to see the value. Is this possible with other Windows C ++ IDEs?

I know that all vector elements are shown in windows Autosand Locals, but my vectors are too long to be practical.

+5
source share
4 answers

Just prefix each []with the help _Myfirstin the "Watch" field:

YourVector._Myfirst[n]
+5
source

The trick here is:

Say what you have std::vector<int> v;and you want to see in the clock v[23]or maybe v[23]..v[23+n]do it:

  • Add a variable to the viewport.
  • Add ,!after the variable name (ex:) v,!to indicate to VS that you want to disable the debugger visualization.
  • Expand the elements of the vector until you see _Myfirst, _Mylastand _Myend. Add _Myfirstto the watch. This is a pointer to the beginning of the vector memory.
  • Remove v,!with a clock if you want.
  • _Myfirst, , + offset, count, offset - , , count - , . : (*((std::_Vector_val<std::_Simple_types<int> >*)(&(*((std::_Vector_alloc<0,std::_Vec_base_types<int,std::allocator<int> > >*)(&(v)))))))._Myfirst + 23, 100. 100 , 23 (, , _Myfirst). offset count (: v[n] offset n count , , .

, Going Native Episode 28 17- , . , .

v[n] = ... + pre_calculate(v[n]) + ...
// You could put a comment like this:
// (*((std::_Vector_val<std::_Simple_types<int> >*)(&(*((std::_Vector_alloc<0,std::_Vec_base_types<int,std::allocator<int> > >*)(&(v)))))))._Myfirst + n, 100
// And when you hover the mouse over the selected expression, you see the evaluation. Much better I think.
+2

MSVC _M_start, _M_finish _M_end_of_storage _Vector_base, .

vector._M_start[n]
0

IDE C++, ; , .

( Borland 6 C++) , , . Visual .

: nameVector.memberWichPointsToTheFirstElement [StartIndex], numElementsDesiredToDisplay.

. , , : .

0

All Articles