Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

C++: Exemple d’une fonction générique pour afficher le contenu d’une liste

 list, list, deque
{filelink=14651}

#include <iostream>
#include
<list>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
 
template <class T>
inline void afficher_elements(const T &coll, const char* optcstr="")
{
    typename T::const_iterator pos;
 
    std::cout << optcstr;
    for (pos=coll.begin(); pos!=coll.end(); ++pos) {
        std::cout << *pos << ' ';
    }
    std::cout << std::endl;
}
 
int main()
{
    list<int> coll;
    vector<char> coll2;
 
    for (int i=1; i<=9; ++i)
	{
        coll.push_back(i);
    }
 
    afficher_elements(coll,"Liste: ");
 
	return 0;
}

No comments yet.

Leave a Comment