Use generic list to create a list of chars : list « list « C++ Tutorial






#include <iostream>
#include <cassert>
#include <list>
#include <algorithm>  // For reverse
using namespace std;



int main()
{
  char x[5] = {'a', 'b', 'c', 'd', 'e'};

  list<char> list1(&x[0], &x[5]);


  reverse(list1.begin(), list1.end());

  list<char>::iterator i;

  cout.precision(10);

  for (i = list1.begin(); i != list1.end(); ++i)
    cout << *i << endl;

  cout << endl;


  return 0;
}
e
d
c
b
a








17.1.list
17.1.1.Four constructors of list
17.1.2.Constructing One Container from Another
17.1.3.Use generic list to create a list of chars
17.1.4.Use generic list to create list of strings
17.1.5.Store class objects in a list
17.1.6.Use std::copy to print all elements in a list
17.1.7.Pass list to a function
17.1.8.Uses ostream_iterator and copy algorithm to output list elements
17.1.9.Add elements in a multiset to a list
17.1.10.Add elements in a set to a list