#include "stdafx.h" #include <string> #include <list> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<string> staff; staff.push_back("Cracker, Carl"); staff.push_back("Cacker, Harry"); staff.push_back("Lam, Larry"); staff.push_back("Sandam, Susan"); /* add a value in fourth place */ list<string>::iterator pos; pos = staff.begin(); pos++; pos++; pos++; staff.insert(pos, "Reindeer, Rudolf"); /* remove the value in second place */ pos = staff.begin(); pos++; staff.erase(pos); /* print all values */ for ( pos = staff.begin(); pos != staff.end(); pos++ ) cout << *pos << "\n"; system("pause"); return 0; }
时间: 2024-10-12 13:46:04