Thread: iterators?

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    23

    iterators?

    Could someone please explain iterators to me? They are mentioned in the C++ strings tutorial, however I honestly just don't understand them at all.

    The part that they are mentioned at are as follows:

    "On the other hand, strings are actually sequences, just like any other STL container, so you can use iterators to iterate over the contents of a string.
    Code:
    string::iterator my_iter;
    for(my_iter = my_string.begin(); my_iter != my_string.end(); my_iter++)
    {
        cout<<*my_iter;
    }
    Note that my_string.end() is beyond the end of the string, so we don't want to print it, whereas my_string.begin() is at the first character of the string.

    Incidentally, C++ string iterators are easily invalidated by operations that change the string, so be wary of using them after calling any string function that may modify the string."

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    You could always look it up.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    23
    Quote Originally Posted by Queatrix View Post
    You could always look it up.
    Thanks for the fast reply. I thought about looking it up, however I also thought that just posting here about it would involve less work for myself, .

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    Why do you even bother programming if you're too lazy to look up such a simple concept ?

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by Desolation View Post
    Why do you even bother programming if you're too lazy to look up such a simple concept ?
    Agreed.

    Being a good programmer means you have to be able to think for yourself and discover how to find solutions to problems you've never encountered. In this day and age, things are easier with the Internet allowing you to find the answers. It's there. Use it.

    I would dare say I believe many people would have been thrilled if they had the Internet hundreds of years ago to find information by themselves.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    A simple search in google would have given you at least a dozen of links explaining what are iterators. A forum is not for asking such simple questions, a forum is for asking questions when you don't understand a concept or an error even though you've searched information on it...

    Edit:

    I also thought that just posting here about it would involve less work for myself
    And this phrase clearly shows that you don't value other people's time.
    Last edited by Desolation; 06-11-2007 at 12:11 PM.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Closed. The OP clearly doesn't want an answer, he just wants to generate work for us and swear at us.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector of strings with iterators.
    By Mario F. in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2006, 12:12 PM
  2. Using reverse iterators in algorithms
    By 0rion in forum C++ Programming
    Replies: 1
    Last Post: 02-27-2006, 03:19 AM
  3. Writing Iterators...
    By Geolingo in forum C++ Programming
    Replies: 6
    Last Post: 05-29-2003, 09:31 PM
  4. accessing vector elements: iterators are faster?
    By Captain Penguin in forum C++ Programming
    Replies: 1
    Last Post: 11-28-2002, 02:27 PM
  5. Generic Progpammimg Iterators
    By rip1968 in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2002, 10:20 AM