当前位置:网站首页>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语言 线性回归的有关方法

JVM内存结构详解

JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)

JS提升:手写发布订阅者模式(小白篇)

Interview Blitz 70: What are sticky packs and half packs?How to deal with it?

移植MQTT源码到STM32F407开发板上

An online JVM FullGC made it impossible to sleep all night and completely crashed~

响应式织梦模板美容整形类网站
随机推荐
Protocol Buffer usage
Jmeter实战 | 同用户重复并发多次抢红包
织梦模板加入php代码
使用员工管理软件,解锁人力生产力新水平,提高人力资源团队灵活性
TP5-NPs负载噻吩类化合物TP5白蛋白纳米粒/阿魏酸钠新糖牛血清蛋白纳米粒
R语言 pca主成分分析的主要方法
牛血清白蛋白刺槐豆胶壳聚糖缓释纳米微球/多西紫杉醇的纳米微球DTX-DHA-BSA-NPs
JSD - 2204 - Knife4j framework - processing - Day07 response results
位运算简介
[译] 容器和 Kubernetes 中的退出码完整指南
淘宝获取收货地址列表的 API
关键字搜索:“淘宝商品 API ”
方舟生存进化是什么游戏?好不好玩
JSD-2204-Knife4j框架-处理响应结果-Day07
移植MQTT源码到STM32F407开发板上
Based on FPGA in any number of bytes (single-byte or multibyte) serial port (UART) to send (including source engineering)
Simple test of the use of iptables
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.2 Early Experience of C Language
JVM内存结构详解
360借条安全专家:陌生微信好友不要轻易加贷款推广多是诈骗