Une seule fonction générique pour afficher tous type de tableau

Author:


Download


#include 
using std::cout;
using std::endl;

template< typename T >
void afficher_tableau( const T *tab, int taille )
{
   for ( int i = 0; i < taille; i++ )
      cout << tab[ i ] << " ";

   cout << endl;
}

int main()
{

   int a[] = { 0, -6, 2, -4, 1, 13 };
   const int taille_a=sizeof(a)/sizeof(a[0]);

   double b[] = { 1.1, 2.2, 3.3, 4.4, 5.5};
   const int taille_b=sizeof(b)/sizeof(b[0]);

   char c[  ] = "Bienvenu";
   const int taille_c=sizeof(c)/sizeof(c[0]);

   afficher_tableau( a, taille_a );  

   afficher_tableau( b, taille_b);  

   afficher_tableau( c, taille_c );
   return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *