fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <utility>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main() {
  8. list<pair<string,int>> l0 { { "name1", 20 }, { "name2", 30 }, { "name3", 40 } };
  9. // for( auto &it : l0 )
  10. // l0 . erase( it );
  11.  
  12. cout << "Containt of the list: "<<endl;
  13. for( auto &my_pair : l0 )
  14. cout <<"\t"<< my_pair.first << ":"<<my_pair.second<<endl;
  15.  
  16. cout << "Deleting content:"<<endl;
  17. for (auto it=l0.begin(); it!=l0.end(); ) {
  18. cout <<"\t"<< it->first << ":"<<it->second<<"...";
  19. it = l0.erase(it);
  20. cout << "remaining "<<l0.size()<< " - delete succesfull" <<endl;
  21. }
  22. cout << "Size:"<< l0.size();
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
Containt of the list: 
	name1:20
	name2:30
	name3:40
Deleting content:
	name1:20...remaining 2 - delete succesfull
	name2:30...remaining 1 - delete succesfull
	name3:40...remaining 0 - delete succesfull
Size:0