多项数据文件输入到类的成员

问题遇到的现象和发生背景

想把txt文件的数据输入到一个有多项成员的类中

问题相关代码,请勿粘贴截图

大概是一个这样的类
class xinxi
{
public:
xinxi() { count++; }
~xinxi() { count--; }
private:
char name[20];//姓名
char subject[10];
char clas[20];//班级
float score,jidian;
static int count;
};
数据文件格式如下
Alex 1 math 90 3.6
Alex 1 english 100 4.0
Alex 1 physics 80 3.6
Peter 1 math 90 3.6
Peter 1 english 70 3.2
Charlie 2 english 80 3.2
Charlie 2 chemistry 100 4.0
David 2 math 60 3.0
David 2 physics 80 3.6
David 2 chemistry 60 3.0
Bob 3 physics 80 3.6
Bob 3 english 90 3.6
Niko 3 math 100 4.0
Niko 3 physics 80 3.2
Niko 3 chemistry 100 4.0

我想要达到的结果

主程序有若干xinxi实例,想依次将数据赋值给xinxi实例

给你一个例子供你参考

#include <fstream>
#include <iostream>
#include <string>
#include <vector>

struct Student {
  std::string name;
  std::string subject;
  std::string className;
  float score;
  float gpa;
};

int main() {
  std::vector<Student> students;
  Student s;
  std::ifstream file("students.txt");
  while (file >> s.name >> s.className >> s.subject >> s.score >> s.gpa)
    students.push_back(s);
  return 0;
}

建议json