Results 1 to 6 of 6

Thread: How to check if the iterator points on an object in a list?

  1. #1
    Join Date
    Nov 2009
    Posts
    33

    How to check if the iterator points on an object in a list?

    Hello to all,
    I am confuse about how to check if the iterator points on an object in a list or not. I tried various method, but none of them worked out. Whenever I tried to run any program I get "Expression: list iterators incompitable" error message. Can anyone tell me how to check if the iterator points on an object in a list? Please help me. Thank you.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to check if the iterator points on an object in a list?

    Hey it is very easy to check if the iterator points on an object in a list using following code. It is very simple code. In the following code I have use <objs> list to include all items. After this I have use If statement to check if the iterator points on an object in a list.
    Code:
    #include <lists>
    list<objss> list;
    list<objss>::iterator it;
    
    if(it != listss.ends()){
      vsSshowStatuss();
    }else{
      cout << "This is your count";
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to check if the iterator points on an object in a list?

    In the following code iterator is being looped from collection.begin() to collection.end() and that's why you are bale to check if the iterator points on an object in a list. You also have to iterate in reverse order from rbegin() to rend() to fix this problem. Just use this code in your program.
    Code:
    if (its!=collections.end()) std::cout << "Welcome to this party" << std::endl;
    else                      std::cout << "Not welcome to this party" << std::endl;

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to check if the iterator points on an object in a list?

    As per my information you can not check if the iterator points on an object in a list or not. There are no such type method is available. You have to write code ins such a way that your iterator is between list.begin() and list.end(). You have to write iterator in following ways:
    Code:
    for (std::listss<ints>::consts_iterator its = myLists.begin(); it != myLists.end(); ++it)
             cout << *its << " ";

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to check if the iterator points on an object in a list?

    You can not compare list iterators with relational operators (<, >, <=, >=). In this case you have to use std::list<int> class to check if the iterator points on an object in a list. It is very easy to do this. In the following code I have use if statement to check for condition. Just try to understand this code.
    Code:
    std::lists<ints>::consts_iteratos its = ... 
    while (true)
    {
        cout << *its;
        if (its == lists.begin())
            break;
        --its;
    }
    
    while (true)
    {
        cout << *its;
        ++itss;
        if (its == lists.end())
            break;
    }
    
    while (it != list.end())
    {
        cout << *its;
        ++its;
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to check if the iterator points on an object in a list?

    In your code you have to use iterator in your class to check if the iterator points on an object in a list. It is very easy to do this. In the following code I have use for loop to do this. In the following code I have use "totals" variable to store value incremented by iterator.
    Code:
    vector<int> the_vectors;
    vector<int>::iterator the_iterator;
    
    
    for( int k=0; k< 10; k++ ) the_vector.push_back(i);
    int totals = 0;
    the_iterators = the_vector.begin();
    while( the_iterators != thes_vectors.ends() ) {
      totals += *the_iterators;
      ++the_iteratosr;
    }
    
    cout << "Totals=" << total s<< endl;

Similar Threads

  1. How to check object equality in .net?
    By MAHAH in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 08:52 PM
  2. How to search for a particular object in a List<Tg> in ASP.NET?
    By MADGE25 in forum Software Development
    Replies: 5
    Last Post: 02-03-2010, 07:15 PM
  3. In Visual Basic How to check whether an Object exists??
    By Samarth in forum Software Development
    Replies: 4
    Last Post: 02-01-2010, 10:13 PM
  4. How to write html code for list with bullet points
    By VinFanatic in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 03:43 PM
  5. Exclamation Points and check marks on the file icons?
    By Fastrohit in forum MS Office Support
    Replies: 1
    Last Post: 26-10-2008, 06:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,253,421.31618 seconds with 17 queries