Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Beginner Q: Viewing the contents of an array in the watch window

Beginner Q: Viewing the contents of an array in the watch window

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structureslearning
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • L Lost User

      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

      A Offline
      A Offline
      arf
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups