结构体02:结构体数组

阅读 177

2022-01-13

#include<iostream>
#include<string>
using namespace std;
//定义结构体 
struct Student{
	string name;
	int age;
	int score;
	
};

int main(){
	//创建结构体数组
	struct Student stuArray[3]{
		{"张三",18,100},
		{"李四",18,100}, 
		{"王五",18,100}  
	}; 
	
	//给结构体数组中的元素赋值
	stuArray[2].name="赵六";
	
	//遍历结构体数组
	for(int i =0;i<3;i++){
		cout<<"姓名:"<<stuArray[i].name<<"  "<<
			  "年龄:"<<stuArray[i].age<<" "<<
			  "成绩:"<<stuArray[i].score<<endl; 
	 } 
		
}

精彩评论(0)

0 0 举报