C++:STL的list

C++:STL的list,第1张

// 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;		//输出字符串
}

运行结果:

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/873080.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存