How to Copy a List in C++ STL? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In C++, a list is a sequence container provided by the STL library that represents a doubly linked list and allows us to store data in non-contiguous memory locations efficiently. In this article, we will learn how to copy one list to another in C++. Input: sourceList = {10, 20, 30, 40, 50};Output: copiedList = {10, 20, 30, 40, 50};Copying a List to Another List in C++To copy a std::list in C++, we can use the default copy constructor which creates a new list that is a copy of an existing list with the same type. It automatically copies all elements from the original list to the new list, maintaining the order. we just have to invoke the copy constructor by passing the source list as an argument. Syntax to Copy a List list<dataType> copiedList(existingList);Here, dataType is the type of the elements stored in the list.copiedList is the new list that we are creating.sourceList is the existing list from which we want to create a copy.C++ Program to Copy One List to Another The below program demonstrates how we can copy a std::list to another list in C++. C++ // C++ program to copy a list to another list #include <iostream> #include <list> using namespace std; int main() { // Creating and initializing an source list list<int> sourceList = { 1, 2, 3, 4, 5 }; // Creating a copied list using the copy constructor list<int> copiedList(sourceList); // Output the contents of the copied list cout << "Copied List: "; for (int num : copiedList) { cout << num << " "; } cout << endl; return 0; } OutputCopied List: 1 2 3 4 5 Time Complexity: O(N), where N denotes the size of the list.Auxiliary Space: O(N) Comment More infoAdvertise with us Next Article Company-wise Practice Problems D denzirop9v Follow Improve Article Tags : C++ Programs C++ STL cpp-list cpp-list-functions CPP Examples +2 More Practice Tags : CPPSTL Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like