7302人加入学习
(18人评价)
C++编程系列 第一季编程基础

制作于2018年2月7日

价格 免费

struct 结构体名字{

float x;

float y;

float z;

}

 

结构体名字  某东西名字{1,5,6} 分别赋值

就可以调用结构体

cout<<赋值东西名字.x 输出某个值

 

结构体名字 某些东西的数组[ ]{ {1,2,3 },{5,6,5 },{ 8,9,4},{ 5,6,7} };

结构体类型数组

 

cout<<某东西数组[1].x<<某东西数组[1].y<<某东西数组[1].z

输出jie'g

 

 

[展开全文]

关键字struct 用于声明结构体

[展开全文]

结构体一个大套餐

可以简化代码量

[展开全文]
01RK · 2020-08-26 · 28-结构体 0

结构体  一种组合类型

数据获得,声明主函数

struct    定义结构体

[展开全文]

#include <iostream>

using namespace std;

 

struct Position{

float x;

float y;

float z;

};

 

int main()

{

//float playerPositionX;

//float playerPostionY;

//float playerPostionZ;

 

Position playerPos = {3, 4, 6.7};

Position playerPos {3, 4, 6.7}; // 省略等号“=”

Position playerPos{ };

cout<playerPos.x<<playerPos.y<<palyerPos.z<<endl; // 346.7

playerPos.y=100;

cout<<playerPos.y<<endl;// 100

 

Position enemyPos;

// 结构体数组

Position enemysPos[]{{1,1,1},{2,4,7},{},{6,4,5},{123,2,2}};

cout<<enemysPos[1].x<<enemysPos[1].y<<enemysPos[1].z<<endl; // 247

 

return 0;

}

掌握语法即可

结构体可以放在函数里面(仅该函数内使用),也可以放在函数外面(都可以使用)

[展开全文]