初始化时可以全部一起赋值struct date today = { 2022,4,25 };
初始化过后只能单独赋值:today.year = 2022;today.month = 4;这样一个一个赋值
//C++
#include <iostream>
using namespace std;
struct T{
string a;
int b;
};
int main()
{
T t;
t = T{"abc", 123};
cout << t.a << ", " << t.b << endl;
}
是不是输入成中文花括号了{}?
结构体不能这样赋值,把这句搬上面去,定义时初始化,改为:
struct date today = { 2022,4,25 };
//today = (struct date){ 2022,4,25 };