// List_example.cpp : 定义控制台应用程序的入口点。 //List #include "stdafx.h" #include#include #include
#include using namespace std; #include "stdafx.h" void PrintLine(string& StringLine); int _tmain(int argc, _TCHAR* argv[]) { list Food; //使用list模板,类型为string Food.push_back( "----食物清单------");//在末尾添加清单 Food.push_back(" 牛奶 "); Food.push_back(" 蓝莓 "); Food.push_back(" 香蕉 "); Food.push_back(" 牛油果 "); for_each(Food.begin(), Food.end(), PrintLine); getchar(); return 0; } void PrintLine(string& StringLine) { cout << StringLine << endl; //输出字符串 }
运行结果:



