Using template functions to output array of different types : container as parameter « STL Introduction « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

template< typename T >
void printArray( const T *array, int count )
{
   for ( int i = 0; i < count; i++ )
      cout << array[ i ] << " ";

   cout << endl;
}

int main()
{
   const int aCount = 5; 
   const int bCount = 7; 
   const int cCount = 6; 

   int a[ aCount ] = { 1, 2, 3, 4, 5 };
   double b[ bCount ] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 };
   char c[ cCount ] = "HELLO";

   printArray( a, aCount );  

   printArray( b, bCount );  

   printArray( c, cCount );  
   return 0;
}
1 2 3 4 5
1.1 2.2 3.3 4.4 5.5 6.6 7.7
H E L L O








14.4.container as parameter
14.4.1.Function with vector as the parameter
14.4.2.Use list as the function parameter
14.4.3.Function with stack as parameter
14.4.4.Using template functions to output array of different types