How to watch vectors more easily?

23 06 2008


Everyone uses vectors and during debugging if we’ve to watch the elements, its a real headache. The usual method that follows is to quick watch the vector and we add index to the _First element. For instance, assume we’ve the vector generated by following code snippet.

// The String Vector.
vector<CString> StringVector;

// Add some strings to it.
StringVector.push_back(_T("WeSeeTips"));
StringVector.push_back(_T("is"));
StringVector.push_back(_T("Cool!"));

For watching it, we quick watch and click the _First member of vector and adds an index to it to skip to the nth element. See the screenshot.

Is there any better way to watch the whole vector instead of this iteration?


Yes! you can. First you’ve to get the vector size by adding “StringVector.size()” to watch window. Then you’ll get the size. Now add “StringVector._First,size” to the watch window. That will show all the elements in that vector. Just see the screenshot.


You can evaluate the same expression in your quick watch window. Have fun!


Targeted Audience – Intermediate.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: