Utilisation de la boucle ‘for each’ pour afficher le contenu d’une collection

Author:

 list, list
{filelink=15132}

#include 
#include

#include 
using namespace std;

class Afficher {
  public:
    template void operator() (T &elem) const {
        cout << elem << ' ';
    }
};

int main()
{
    list coll;

    // insérer 18 éléments dans la list
    for (int i=-9; i<=9; ++i) {
        coll.push_back(i);
    }

    // Afficher les éléments
    for_each (coll.begin(), coll.end(),
              Afficher());
    cout << endl;

	return 0;
}

Leave a Reply

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