// Phil Ottewell's STL Course - http://www.pottsoft.com/home/stl/stl.htmlx // // Example 3.3 © Phil Ottewell 1997 // // Purpose: // Demonstrate list container // ANSI C Headers #include // C++ STL Headers #include #include #include #include #ifdef _WIN32 using namespace std; # pragma warning(disable:4786) // We know basic_string generates long names :-) #endif int main( int argc, char *argv[] ) { string things[] = { "JAF", "ROB", "PHIL", "ELLIOTT", "ANDRZEJ" }; const int N = sizeof(things)/sizeof(things[0]); list< string > yrl; list< string >::iterator iter; for ( int i = 0; i < N; ++i) yrl.push_back( things[i] ); for ( iter = yrl.begin(); iter != yrl.end(); ++iter ) cout << *iter << endl; // Find "ELLIOTT" cout << "\nNow look for ELLIOTT" << endl; iter = find( yrl.begin(), yrl.end(), "ELLIOTT" ); // Mary should be ahead of Elliott if ( iter != yrl.end() ) { cout << "\nInsert MARY before ELLIOTT" << endl; yrl.insert( iter, "MARY" ); } else { cout << "\nCouldn't find ELLIOTT" << endl; } for ( iter = yrl.begin(); iter != yrl.end(); ++iter ) cout << *iter << endl; return( EXIT_SUCCESS ); }