CLB3ATMP.CPP

Figure 1. z/OS® XL C++ template program
#include <list>
#include <string>
#include <iostream>
using namespace std;

template <class Item> class IOList {
  public:
    IOList() : myList() {}
    void write();
    void read(const char *msg);
    void append(Item item) {
      myList.push_back(item);
    }
  private:
    list<Item> myList;
};

template <class Item> void IOList<Item>::write() {
  ostream_iterator<Item> oi(cout, " ");
  copy(myList.begin(), myList.end(), oi);
  cout << '\n';
}

template <class Item> void IOList<Item>::read(const char *msg) {
  Item item;
  cout << msg << endl;
  istream_iterator<Item> ii(cin);
  copy(ii, istream_iterator<Item>(), back_insert_iterator<list<Item> >(myList));
}

int main() {
  IOList<string> stringList;
  IOList<int>    intList;
  
  char line1[] = "This program will read in a list of ";
  char line2[] = "strings, integers and real numbers";
  char line3[] = "and then print them out";
  
  stringList.append(line1);
  stringList.append(line2);
  stringList.append(line3);
  stringList.write();
  intList.read("Enter some integers (/* to terminate)");
  intList.write();
  
  string name1 = "Bloe, Joe";
  string name2 = "Jackson, Joseph";
 
  
  if (name1 < name2)
    cout << name1 << " comes before " << name2;
  else
    cout << name2 << " comes before " << name1;
  cout << endl;
  int num1 = 23;
  int num2 = 28;
  if (num1 < num2)
    cout << num1 << " comes before " << num2;
  else
    cout << num2 << "comes before " << num1;
  cout << endl;
  
  return(0);
}