三种方式视情况而定,看自己喜欢哪一种
#include <iostream>
#include <string>
using namespace std;
struct student
{
string name;
int score;
}three;
int main()
{
struct student one;
one.name = "张三";
one.score = 99;
cout << "姓名:" << one.name << " 分数:" << one.score << endl;
struct student two = { "李四", 89 };
cout << "姓名:" << two.name << " 分数:" << two.score << endl;
three.name = "赵五";
three.score = 78;
cout << "姓名:" << three.name << " 分数:" << three.score << endl;
system("pause");
return 0;
}
结果
姓名:张三 分数:99
姓名:李四 分数:89
姓名:赵五 分数:78
请按任意键继续. . .