Search
 
SCRIPT & CODE EXAMPLE
 

CPP

cpp std list example

#include <algorithm>
#include <iostream>
#include <list>
 
int main()
{
    // Create a list containing integers
    std::list<int> l = { 7, 5, 16, 8 };
 
    // Add an integer to the front of the list
    l.push_front(25);
    // Add an integer to the back of the list
    l.push_back(13);
 
    // Insert an integer before 16 by searching
    auto it = std::find(l.begin(), l.end(), 16);
    if (it != l.end()) {
        l.insert(it, 42);
    }
 
    // Print out the list
    std::cout << "l = { ";
    for (int n : l) {
        std::cout << n << ", ";
    }
    std::cout << "};
";
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: ray sphere intersection equation 
Cpp :: c++ greatest common divisor 
Cpp :: how to easily trim a str in c++ 
Cpp :: convert integer to string c++ 
Cpp :: c++ program transpose of matrix 
Cpp :: change int to string c++ 
Cpp :: the code execution cannot proceed because glew32.dll was not found 
Cpp :: vector reverse function in c++ 
Cpp :: c++ default parameters 
Cpp :: reading file c++ 
Cpp :: upcasting in c++ 
Cpp :: reverse function in cpp string 
Cpp :: pointer address to string 
Cpp :: C++ Vector Iterator Syntax 
Cpp :: c++ code for bubble sort 
Cpp :: int main() { 
Cpp :: cannot jump from switch statement to this case label c++ 
Cpp :: long to string cpp 
Cpp :: 3d projection onto 2d plane algorithm 
Cpp :: c++ progress bar 
Cpp :: cpp return array 
Cpp :: how to empty string c++ 
Cpp :: if statement c++ 
Cpp :: pure virtual function in c++ 
Cpp :: stack c++ 
Cpp :: vector c++ 
Cpp :: c++ access second last element of vector 
Cpp :: c++ reverse part of vector 
Cpp :: how to write a template c++ 
Cpp :: variables in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =