Script started on Thu Mar 22 01:58:33 2001
[tsaiwn@ccbsd3] vectorSTK> g++ mymain6.cpp 
[tsaiwn@ccbsd3] vectorSTK> ./a.out 
53770880
[tsaiwn@ccbsd3] vectorSTK> 

[tsaiwn@ccbsd3] vectorSTK> cat -n mystk6.h
     1  //mystk6.h -- @CopyLeft by tsaiwn@csie.nctu.edu.tw
     2  #ifndef _MYSTK6_H_
     3  #define _MYSTK6_H_
     4  //implement a template class Stack using a vector
     5  #include <vector>
     6  using namespace std;
     7  template <class T>
     8  class MyStack {
     9     vector <T> x; 
    10  public:
    11     void push(const T& y) {
    12        x.push_back(y);
    13     }
    14     T top( ) {
    15       return x.back( );
    16     }
    17     void pop( ) {
    18       x.pop_back( );
    19     }
    20     bool empty( ) { return x.begin() == x.end(); }
    21  };
    22 #endif 
[tsaiwn@ccbsd3] vectorSTK> cat -n mymain6.cpp
     1  // mymain6.cpp;  g++ mymain6.cpp  ; ./a.out
     2  #include "mystk6.h"
     3  //注意以下是 1999之後的 C++ 新寫法, 舊法使用 <iostream.h>
     4  #include <iostream>
     5  using namespace std;
     6  int main( ){
     7     MyStack <int> x;    // 注意這!
     8     x.push(880);
     9     x.push(770);
    10     x.push(53);
    11     while(!x.empty()){
    12        cout << x.top();  x.pop();
    13     }
    14     cout << endl;
    15  } // main( 
[tsaiwn@ccbsd3] vectorSTK> g++ mymain6.cpp
[tsaiwn@ccbsd3] vectorSTK> ./a.out 
53770880
[tsaiwn@ccbsd3] vectorSTK> exit
exit

Script done on Thu Mar 22 01:58:58 2001