Thread: Problem with vector iterator

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Problem with vector iterator

    Hello.
    I began playing around a little with iterators for an std::vector a while back for my programming project I'm currently working on, and am basically trying to use them right now to access a vector object (stored inside of a map)'s elements (which are instances of a struct named "S_html_attr_value"), and modify them to add some information not originally given in an earlier class I built (such as setting a 'notes' and 'tips' property for them). Now, my original thought was that I could modify the vector inside of the map without having to copy the vector content into a new vector object (and then copy it back into the map after removing the old vector, once the changes are made...), and simply modify the original vector inside of the map instead. However, attempting to do this has run me into a number of issues (starting with a segfault, continuing with a segfault even after I tried a number of things to fix it, and now when I C/Ped it into codepad.org's, and modified the original concept a little, the error its giving me now (at least on codepad.org) complains about "trying to increment a singular iterator", even though the iterator is supposed to be a random access iterator which shouldn't have any problems. I suspect it has something to do with std::map's behavior with vector mapped values, since using just a vector and no map, the code works just fine. Anyway, I tried many different things, which I wont go to any great length to explain right now, as that would take too long.

    Here is basically where I'm stuck right now (click the link to see the
    code):

    C++ code - 158 lines - codepad

    The line of most interest is 153. Try commenting it out, and you'll see the error disappears.
    Last edited by Programmer_P; 01-03-2013 at 07:47 PM.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using a vector iterator in a loop.
    By M.Richard Tober in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2011, 01:53 PM
  2. vector and iterator problem
    By BeBu in forum C++ Programming
    Replies: 10
    Last Post: 03-11-2009, 07:38 AM
  3. Vector Iterator Help
    By (TNT) in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2007, 02:53 PM
  4. vector<object>::iterator Help
    By The Brain in forum C++ Programming
    Replies: 16
    Last Post: 03-26-2006, 07:22 PM
  5. Iterator _ erasing from a vector help
    By Hexxx in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 07:43 PM