8.3结构体数组

#include <iostream>
#include<string>
using namespace std;
//1.创建一个结构体
struct student
{
	string name;
	int age;
	int score;
};
int main8_3()
{
	
	//2.创建一个结构体数组
	struct student starray[3] =
	{
		{ "zz", 18, 100 },
		{ "xx", 28, 99 },
		{ "cc", 38, 66 },
	};
	//3.遍历结构体数组
	starray[2].name = "aaa";
	for (int i = 0; i < 3; i++)
	{
		cout << "sss" << starray[i].name << endl;
	}
	system("pause");
	return 0;
}

# 8.2结构体的使用

#include <iostream>
using namespace std;
#include<string>
/*
语法:struct 结构体名(结构体成员列表)

*/

struct student
{
	string name;
	int age;
	int score;
}s3;
//创建具体学生,有三种
/*
	struct student s1
	struent student s1={...};
	在定义结构体后创建
*/

int main8_1()
{
	//下面struct可以省略
	struct student s1;
	s1.age = 10;
	s1.name = "ddddd";
	s1.score=88;

	struct student s2 = {"dddd",11,22};

	cout << "姓名:" << s2.age << endl;
	system("pause");
	return 0;
}

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐