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. difference b/w iterators and indexing for STL

difference b/w iterators and indexing for STL

Scheduled Pinned Locked Moved C / C++ / MFC
c++dockerquestion
3 Posts 3 Posters 0 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.
  • H Offline
    H Offline
    hawk23reddy
    wrote on last edited by
    #1

    hi every one, we for an STL container we can use both iterator or indexing method to access the container data, but still y iterators are preferred i mean what is advantage of using iterator over legecy indexing... please answer me... if u feel silly still iam the begineer and even tried to google but didnt found the destiny..

    M S 2 Replies Last reply
    0
    • H hawk23reddy

      hi every one, we for an STL container we can use both iterator or indexing method to access the container data, but still y iterators are preferred i mean what is advantage of using iterator over legecy indexing... please answer me... if u feel silly still iam the begineer and even tried to google but didnt found the destiny..

      M Offline
      M Offline
      minkowski
      wrote on last edited by
      #2

      Hi, This is about the only book you will ever need on the STL. http://www.amazon.co.uk/C-Standard-Library-Tutorial-Reference/dp/0201379260/ref=sr_1_3?ie=UTF8&s=books&qid=1247072015&sr=8-3[^ :) As for your question, it depends on which container you have. If you have a List you cannot use indexing. You must use an iterator to access it. Vector, dequeue offer indexing (random access) and so are faster to access than iterating through every element.

      1 Reply Last reply
      0
      • H hawk23reddy

        hi every one, we for an STL container we can use both iterator or indexing method to access the container data, but still y iterators are preferred i mean what is advantage of using iterator over legecy indexing... please answer me... if u feel silly still iam the begineer and even tried to google but didnt found the destiny..

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #3

        Iterators are a more generic and flexible concept than indices. They allow you to access the item they reference without having to refer to the parent container. Indices can't do that - they need to be explicitly used with the container they index. Things like polymorphic algorithms (like in the STL header algorithm) would be tricky to implement with indices... The Wikipedia page on iterators[^] has quite a good explanation.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        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