Visual Studio Debugging Immediate Window

Visual Studio supports many ways of debugging. The immediate window comes in very handy when it comes to examining specific variable values (e.g. what's the value of the 20000th element of this vector?).

You can call any function and print all data present, as long as it hasn't been optimized out by the compiler. However, the vector query mentioned before will not work right away (assuming there's a std::vector<...> vec in the current working set):

// error: overloaded operator not found or
// No "[]"-operator available for this operand.
// error: symbol is ambiguous or
// error: the function is not available (it might have been subject to compiler optimizations).

However, you can easily work around that by using the vec._Myfirst field that holds a pointer to the first vector element and access the i-th element by using vec._Myfirst[i].

Similar constructs can help with most containers by looking at their headers (see also here).

Looking around further for clever uses of the immediate windows leeds to another entry on stackoverflow and a handy list of special commands available for VS2008 & VS2010 on MSDN. These range from searching through a chunk of memory for a certain value, to display disassembly and the current thread status.

Unfortunately, they seem to have been removed in the newer versions of VS. The overview page for these versions can be found here on MSDN.