当前位置:网站首页>51.【结构体初始化的两种方法】
51.【结构体初始化的两种方法】
2022-08-01 21:12:00 【李在奋斗……】
【直接初始化法】
#include <iostream>
#include <string.h>
using namespace std;
struct MyStruct
{
int number;
string name;
};
MyStruct my_struct = { 21032114, "李威涛" }; //直接初始化
int main()
{
cout << my_struct.name << endl;
}

【逐个赋值法】
`#include <iostream>
#include <string.h>
using namespace std;
struct MyStruct
{
int number;
string name;
};
int main()
{
MyStruct my_struct; //逐个赋值法
my_struct.name = "李威涛";
cout << my_struct.name << endl;
}

边栏推荐
猜你喜欢
随机推荐
XSS漏洞
C Pitfalls and Defects Chapter 7 Portability Defects 7.6 Memory Location 0
Popular explanation: what is a clinical prediction model
C专家编程 第1章 C:穿越时空的迷雾 1.5 今日之ANSI C
C Pitfalls and pitfalls Appendix B Interview with Koenig and Moo
How to encapsulate the cookie/localStorage sessionStorage hook?
测试的意义并不是能找到全部的缺陷
LeetCode每日一题(1807. Evaluate the Bracket Pairs of a String)
空间数据库开源路,超图+openGauss风起禹贡
织梦发布文章提示body has not allow words错误
这些 hook 更优雅的管理你的状态
微服务负载均衡器Ribbon
Get started with Grafana in 15 minutes
tiup mirror
tiup mirror merge
Telnet弱口令渗透测试
Pytorch框架学习记录12——完整的模型训练套路
Pytorch框架学习记录8——最大池化的使用
C专家编程 第1章 C:穿越时空的迷雾 1.2 C语言的早期体验
15 分钟带你入门 Grafana







![漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]](/img/37/09ab9b5a490c6ab9bc7991ecc4c8f4.png)

