Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:54:04+00:00 2026-05-11T11:54:04+00:00

I have a program which is like this list<int>:: iterator n = alist.begin(); while(n!=

  • 0

I have a program which is like this

list<int>:: iterator n = alist.begin(); while(n!= (list<int>::iterator)0) {     printf('Element is %d\n',*n);     n = alist.erase(n); } 

So here i am comparing iterator with zero. but after deleting the last element the compiler is showing this error.

 *** glibc detected *** ./new: free(): invalid pointer: 0xbf99cb10 *** ======= Backtrace: ========= /lib/libc.so.6[0xb7d956e1] /lib/libc.so.6(cfree+0x89)[0xb7d96d79] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb7f3ff81] ./new[0x8048c81] ./new[0x8048ca6] ./new[0x8048d07] ./new[0x8048d39] ./new(__gxx_personality_v0+0x216)[0x804888e] /lib/libc.so.6(__libc_start_main+0xdc)[0xb7d46f9c] ./new(__gxx_personality_v0+0x49)[0x80486c1] ======= Memory map: ======== 08048000-0804a000 r-xp 00000000 08:09 3704751    /home/sathya/chaithra/archivesthrash/new 

If I want the iterator to be zero if the queue/list is empty.. what i should do? Because in my project I need to compare this iterator with zero only and not with alist.end().. What may be the probable solution to this…?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:54:05+00:00Added an answer on May 11, 2026 at 11:54 am

    Why do you think the iterator will ever ‘be zero’? Iterators are not pointers or indexes. If you need to check if a container is empty, use the empty() member function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program which is more or less like this : #include <list>
I have a thread which produces some data (a python list) and which shall
I am trying to write a program to simulate a card game. I have
I have a number of Python generators, which I want to combine into a
EDIT : I shouldn't be coding when this tired. I was compiling a different
Good night everyone, This question leaves me a little embarassed because, of couse, I
I have a csv file where each row defines a room in a given
I'm designing a weather program where I need to keep track of certain things
I've got a list of definitions: MASTER , SLAVE0 , SLAVE1 , ... SLAVE9
C++. Its may be more question of debugging in Visual Studio and working with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.