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. iterator

iterator

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
5 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.
  • K Offline
    K Offline
    knoxplusplus
    wrote on last edited by
    #1

    Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-

    S Z 2 Replies Last reply
    0
    • K knoxplusplus

      Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-

      S Offline
      S Offline
      Sarath C
      wrote on last edited by
      #2

      // Create a list of characters
      list charList;
      for( int i=0; i < 10; i++ ) {
      charList.push_front( i + 65 );
      }
      // Display the list
      list::iterator theIterator;
      for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) {
      cout << *theIterator;
      }

      SaRath.
      "It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++

      1 Reply Last reply
      0
      • K knoxplusplus

        Can me somebody give an example of an simple iterator (such as STL but simple) ? Thanks. -:KNOX:-

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        An example of what an iterator class looks like or how to use them? If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        K 1 Reply Last reply
        0
        • Z Zac Howland

          An example of what an iterator class looks like or how to use them? If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          K Offline
          K Offline
          knoxplusplus
          wrote on last edited by
          #4

          Yes an class example. -:KNOX:- -- modified at 13:39 Thursday 29th June, 2006

          Z 1 Reply Last reply
          0
          • K knoxplusplus

            Yes an class example. -:KNOX:- -- modified at 13:39 Thursday 29th June, 2006

            Z Offline
            Z Offline
            Zac Howland
            wrote on last edited by
            #5

            The most basic example of an iterator is just a pointer:

            char buffer[100] = "0";	// create a "container"
            char* it = buffer;	// point to the first element in the buffer
            for (int i = 0; i < 100; ++i)	// iterate through the entire container
            {
            	*(it++) = 'a';		// set each element to 'a' and increment iterator
            }
            

            A more indepth example would include writing a basic container class and an iterator class (iterators don't mean much without a corresponding container). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            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