#include<iostream>
#pragma once;
#include<string>//字符类型
#include<vector>
using namespace std;
class student{
public:
string name;//在c++中,字符类型用string
int age;
double XH;
int BJ;
void printfname() {
cout << name << endl;
}
void printfage() {
cout << age << endl;
}
void printfXH() {
cout << XH << endl;
}
void printfBJ() {
cout << BJ << endl;
}
};
int main() {
//创建一个学生类型的数组,利用cin进行输入
vector<student> vec(3);//<>中表示的是数组的类型,可以是类的名
for (int i = 0; i < 3; i++) {
cout << "输入第" << i << "个" << endl;
cin >> vec[i].name >> vec[i].XH;
for (int i = 0; i < 3; i++) {
if (vec[i].XH == 2) {
vec[i].printfname();//调用类中的函数
}
}
}
return 0;
}
利用类和动态数组进行结合,统计管理信息(代替结构体和链表的结合)