Answers for "how to add elements in a list in C++"

C++
0

c++ append to list

// list::push_back
#include <iostream>
#include <list>

int main ()
{
  std::list<int> mylist;
  int myint;

  std::cout << "Please enter some integers (enter 0 to end):n";

  do {
    std::cin >> myint;
    mylist.push_back (myint);
  } while (myint);

  std::cout << "mylist stores " << mylist.size() << " numbers.n";

  return 0;
}
Posted by: Guest on May-28-2020
0

c++ list add

list<int> myList = list<int>();

//add a 4 to the end of the list
myList.push_back(4);

//add a 5 to the begining of the list
myList.push_front(5);
Posted by: Guest on March-29-2021

Code answers related to "how to add elements in a list in C++"

Browse Popular Code Answers by Language