#include <iostream>
struct student {
int a;
int b;
int add(){ //在结构体内封装了函数
return a+b;
}
};
int main(){
student s={10,20};
//c++时struct 可以省略
int x=s.add(); printf("%d\n",x); }
C++ 结构体
原创
©著作权归作者所有:来自51CTO博客作者天子骄龙的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:C++学习目录
下一篇:c--文件读写--文本读写
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
结构体大小计算-结构体对齐
计算某一结构体大小:方法以及规则。
偏移量 #pragma 结构体 结构体大小计算 -
结构体04:结构体嵌套结构体
#include<iostream>#include<string>using namespace std;//定义结构体 学生 str
c++ visual studio 动态规划 #include ios -
认识结构体中嵌套结构体
结构体中嵌套结构体
数组 嵌套 #include 结构体中嵌套结构体