Beginner Q: Viewing the contents of an array in the watch window
-
Hello, how can I view the items of an array or an MFC Collection in the watch view? Let's say I have an CObArray named m_Array. Now I've typed into the watch window "m_Array[0]" to have a look at the first item in the array, but this doesn't work. Any ideas are very welcome. Matthias
-
Hello, how can I view the items of an array or an MFC Collection in the watch view? Let's say I have an CObArray named m_Array. Now I've typed into the watch window "m_Array[0]" to have a look at the first item in the array, but this doesn't work. Any ideas are very welcome. Matthias
For a CArray you have to dereference the internal data pointer to the C style array within the CArray. Any collection not using standard C style arrays for data storage, which I believe is everything but CArray derivatives, will not likely have its contents aligned in a contiguous portion of memory like a CArray will. So viewing such a container's contents would probably be very difficult if not impossible. However, viewing a CArray is easy. For example, if you are stepping through a class with a CArray derived data member named m_array you can see the contents of index 4 by entering this in the watch window: *m_array.m_pData[ 4 ] This assumes that that the array has a size of at least 5. Overstepping the allocated size of the array will probably not hurt in this situation but you will see garbage instead of what you expect to see. Just think of the watch window as a way to execute a limited line of code. Virtually any syntax you would use in your program should be valid in the watch window. However, don't forget about the scope of the data you want to watch. It's easy to assume that what you put in should work and then believe that the problem is not yours when it doesn't work as anticipated.