0
点赞
收藏
分享

微信扫一扫

结构体02:结构体数组

月孛星君 2022-01-13 阅读 177
c++结构体
#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 条评论