栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

list中的pop是否会删除元素的内容?答:不会

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

list中的pop是否会删除元素的内容?答:不会

#include 
#include 

using namespace std;

struct man{
	int ID;
	string name;
	int age;
}ap, bp;

int main()
{
	list Ltest;
	man p_sruct;
	list::iterator iter;
	
	ap.age = 18;
	ap.ID = 1;
	ap.name = "lhonw";
	
	bp.age = 100;
	bp.ID = 5;
	bp.name = "liuz";
	
	Ltest.push_back(ap);
	Ltest.push_back(bp);
	//list的front方法是返回list中节点保存的类型
	//这里保存的是结构体,所以返回的是结构体
	p_sruct = Ltest.front();
	
	for(iter = Ltest.begin(); iter != Ltest.end(); iter++)
	{
		cout << iter->age << endl;
		//把第一个元素从list中弹出
		if(iter->age == 18)
		{
			Ltest.pop_front();
		}
	}
	
	
	for(auto iter = Ltest.begin(); iter != Ltest.end(); iter++)
	{
		cout << "2: " << iter->age << endl;
	}
	//结构体对象获取元素用点运算符
	cout << "baocun: " << p_sruct.age << endl;
	
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/605049.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号