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 787047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:08:25+00:00 2026-05-14T21:08:25+00:00

I want put a value from front of the list into an another list

  • 0

I want put a value from front of the list into an another list but I am getting an error.

for exmaple

List<int> li;
List<int> li2;

.............
.............

li2.push_back(li.front()); // this statement doesnt work for me. 

Can someone please help me.

example code:

   list<int> li;
   list<int> li2;
   li.push_back(1);
   li.push_back(2);
   li.push_back(3);

   for(int i=0;i<3;i++)
   {

    cout<<li.front()<<endl;
    li2.push_back(li.pop_front());

   }
  • 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-14T21:08:26+00:00Added an answer on May 14, 2026 at 9:08 pm

    Also, Be aware that when the list is empty, the pop_front() and pop_back() will throw exceptions – resulting in segmentation fault. So it is mandatory to check the size of the list
    i. directly – using the list function
    ii.indirectly using the for loop as shown in the program.

    Sample Code

    #include <iostream>
    #include <list>
    using namespace std;
    
    
    int main( int argc, char *argv[])
    {
    
        list<int> li;
        li.pop_front();
    
        return 0;
    }
    

    Ouput

    -laptop:~/Study/Pgm$ ./test
    Segmentation fault

    I think this is the behaviour in all OS, I use g++ (4.4.1) on Linux platform.

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

Sidebar

Related Questions

I want to put a value returned from a function into ConcurrentHashmap like that
I have a drop down list and I want the selected value to put
I want to transfer a String value from one class to another class in
I've got a value type that I want put into a map. It has
I'm learning OOP in PHP and I want to put value from variable to
i have put fckeditor in jsp page. I want to get the value whatever
I want to put two side by side on another (I have three )
I want to put the apk file into the Kindle Fire storage(through USB cable)
Respected Users, I am extracting data using data set. I want to put value
I want to remove element from queue with specific value. How to do such

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.