#include #include #include #include using namespace std; void write( const string& s ) { cout << s << endl; } int main( int argc, char* argv[] ) { list lst; string s = "knife"; lst.push_front( s ); s = "fork"; lst.push_back( s ); s = "spoon"; lst.push_back( s ); // A list doesn't have random access, so // use for_each() instead for_each( lst.begin(), lst.end(), write ); return 0; }