Thread: vector : accessing values

  1. #1
    Registered User
    Join Date
    Feb 2006

    vector : accessing values

    eg: vector<int> listOfValues

    Vectors can be accessed by index like listOfVaules[9]
    by iterator.

    which is the best way of accessing? is accessing by index a bad practice?


  2. #2
    Registered User
    Join Date
    Jan 2005
    No, it is not bad practice.

    Better practice might be to use at() instead of operator[] with an index to help avoid using invalid indexes. You should be fine with any of those options, though.

    Note that depending on the situation, using an index or using an iterator might be more clear to a reader of the code than the other option. Often that's the most important factor in your choice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. disposing error
    By dropper166 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2009, 11:53 PM
  2. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  3. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  4. Replies: 1
    Last Post: 02-03-2005, 03:33 AM
  5. Checking ascii values of char input
    By yank in forum C Programming
    Replies: 2
    Last Post: 04-29-2003, 07:49 AM