Thread: contents of a vector object in ddd

  1. #1
    external validation
    Join Date
    Dec 2004
    Posts
    9

    contents of a vector object in ddd

    When using ddd (Data Display Debugger) to debug C code, it can be used to look directly inside the contents of an array, by right-clicking on the array name and selecting "display".
    In my case this has proved invaluable for looking at a binary tree data structure whose nodes contain arrays.

    However...

    I've just moved the program to C++, and started to use vectors instead of arrays.

    Now I can't use ddd to look at the entire contents of a vector.
    It displays the name of the vector and the phrase <no data fields>

    If anybody knows how to get ddd to display vectors, I'd be much obliged for their advice.

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    It depends on what debugger you're using; MSVC 2005 (free!) by default seems to allow you to view the contents of STL containers. Unless the feature is built-in somehow, I doubt any amount of tweaking will help short of manually displaying the contents of each vector as part of your program.

    Alternately, you can try copying individual elements of the vector out, and view the values stored in the temporary variables.
    Code:
    int value;
    for(std::vector<int>::iterator it = theVector.begin(); it != theVector.end(); ++it)
       value = *it;  //In the debugger, watch value change as you run through the loop.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I don't know about ddd, but because the vector is guaranteed to use contiguous storage for its elements, you can use &v[0] to get the address of the first element and just treat it like a regular array.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    On the other hand, since [] is a function for vector, the ddd might not be able to evaluate the expression.

    However, it should be possible to look at its private data members, including the pointer to the actual memory. Which should make your ddd list the vector's content.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Swap the file contents
    By jayfriend in forum C Programming
    Replies: 5
    Last Post: 01-16-2007, 10:36 PM
  3. controlling contents of a linked list
    By jaro in forum C Programming
    Replies: 7
    Last Post: 05-04-2006, 12:31 AM
  4. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  5. combining file contents with command line
    By pxleyes in forum C Programming
    Replies: 4
    Last Post: 04-12-2004, 10:27 PM