vector resizing

This is a discussion on vector resizing within the C++ Programming forums, part of the General Programming Boards category; Okay, thanks....

  1. #16
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Okay, thanks.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #17
    Registered User
    Join Date
    Apr 2003
    Quote Originally Posted by dwks
    Yes, but my vector isn't resizing at all. I get a segmentation fault!
    calls the operator[]() function. Like an array, a vector indexes its elements, and if the index doesn't exist then the operator[]() function fails.

    Vectors grow automatically in size when you add elements to the vector. There are several functions defined to allow you to add elements to a vector. However, operator[]() does not add elements to the vector--it tries to access elements that already exist. In a map<>, operator[]() does add elements to the map, but it doesn't work the same way with a vector.

    If you want to add elements to a vector, then you have to use functions that do that.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21