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

  • Home
  • SEARCH
  • 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 746411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:05:17+00:00 2026-05-14T14:05:17+00:00

#include <list> using std::list; int main() { list <int> n; n.push_back(1); n.push_back(2); n.push_back(3); list

  • 0
#include <list>
using std::list;

int main()
{
    list <int> n;
    n.push_back(1);
    n.push_back(2);
    n.push_back(3);

    list <int>::iterator iter = n.begin();
    std::advance(iter, n.size() - 1); //iter is set to last element
}

is there any other way to have an iter to the last element in list?

  • 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. Editorial Team
    Editorial Team
    2026-05-14T14:05:17+00:00Added an answer on May 14, 2026 at 2:05 pm

    Yes, you can go one back from the end. (Assuming that you know that the list isn’t empty.)

    std::list<int>::iterator i = n.end();
    --i;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <list> #include <set> #include <iterator> #include <algorithm> using namespace std; class MyContainer {
#include <iostream> #include <vector> #include <list> using namespace std; int main() { vector<list<string> >
#include<iostream> #include<time.h> #include<list> #include<stdlib.h> #include<fstream> using namespace std; typedef struct diskBtNode { int parent;
#include <iostream> using namespace std; struct list { int data; list *next; }; list
This is my current code: #include <list> #include <string> using std::string; using std::list; int
#include <iostream> #include Student.h #include SortedList.h using namespace std; #define BOUNDS 100 int main()
#include <list> using std::list; class foo { ... class bar : public foo {
here is my code for xor linked list implementation #include<iostream> using namespace std; struct
I have the following code to test memory deallocation using a std::list container: #include
#include <iostream> using namespace std; struct Node { int item; // storage for the

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.