题解 | #结构体简单使用#
结构体简单使用
https://www.nowcoder.com/practice/87c31efeb07b496cb88b137b54b98330
//一般用法
#include <iostream>
#include <string>
using namespace std;
//c++23及以后官方内置了一个包括绝大部分库的调用方案,可以直接替代近乎全部#include,其语法为import std;
struct student {
std::string name{};
unsigned short age{};
double height{};
};
int main() {
student s;
auto& [x,y,z]=s; //结构化绑定,编译器自动匹配类型并绑定数据
std::cin>>x>>y>>z;
std::cout<<x<<" "<<y<<" "<<z;
//或std::print("{} {} {}",x,yz,); (since from c++23)
return 0;
}
查看9道真题和解析