Use generic list to create list of strings : list « list « C++ Tutorial






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



int main()
{
  string x[5] = {"asdf", "1234", "2345", "6789", "0000"};

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


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

  list<string>::iterator i;

  cout.precision(10);

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

  cout << endl;


  return 0;
}
0000
6789
2345
1234
asdf








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