当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
C专家编程 序
R语言 线性回归的有关方法
Classification interface, Taobao classification details API
案例:MySQL主从复制与读写分离
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.2 Early Experience of C Language
How to encapsulate the cookie/localStorage sessionStorage hook?
图的邻接矩阵存储
C语言_联合体共用体引入
记录第一次给开源项目提 PR
MySQL Syntax Basics
How to choose Visibility, Display, and Opacity when interacting or animating
C语言_typedef和结构体
How to make the timer not execute when the page is minimized?
Pytorch框架学习记录10——线性层
附录A printf、varargs与stdarg A.3 stdarg.h ANSI版的varargs.h
这些 hook 更优雅的管理你的状态
【中文树库标记---CTB】
和我一起写一个音乐播放器,听一首最伟大的作品
【Unity实战100例】文件压缩Zip和ZIP文件的解压
Transformer学习