C++: Modifier une liste via un itérateur

Author:

 list, list
Download


#include 
#include

using namespace std;

int main()
{
  list liste; 

  for(int i=0; i<27; i++)
	  liste.push_back(i+'a');

  cout << "Taille de la liste = " << liste.size() << endl;

  cout << "Contenu de la liste: ";
  list::iterator p = liste.begin();
  while(p != liste.end())
  {
    cout << *p << " ";
    p++;
  }
  cout << endl;

  // Modifier le contenu de la liste
  p = liste.begin();
  int x=0;
  while(p != liste.end())
  {
    *p = x + 'A';
    p++;
	x+=1;
  }

  cout << "Contenu Modifié: ";
  p = liste.begin();
  while(p != liste.end()) {
    cout << *p << " ";
    p++;
  }
  cout<
    

Leave a Reply

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