(草稿)
学生信息默认存储在同文件夹下的 test01.txt 文件中
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const string FILENAME = "test01.txt";
struct Student
{
string id;
string name;
float chi;
float math;
float eng;
Student(string id, string name, float chi, float math, float eng) {
this->id = id; this->name = name; this->chi = chi; this->math = math; this->eng = eng;
}
};
struct MS
{
int m_StuNum;
Student ** m_StuArr;
bool m_FileIsEmpty;
MS() {
ifstream ifs;
ifs.open(FILENAME, ios::in);
if (!ifs.is_open())
{
cout << "文件不存在" << endl;
this->m_StuNum = 0;
this->m_FileIsEmpty = true;
this->m_StuArr = NULL;
ifs.close();
return;
}
char ch;
ifs >> ch;
if (ifs.eof())
{
cout << "文件为空!" << endl;
this->m_StuNum = 0;
this->m_FileIsEmpty = true;
this->m_StuArr = NULL;
ifs.close();
return;
}
int num = this->get_StuNum();
this->m_StuNum = num;
this->m_FileIsEmpty = false;
this->m_StuArr = new Student *[this->m_StuNum];
init_Stu();
}
~MS() {
if (this->m_StuArr != NULL)
{
delete[] this->m_StuArr;
}
}
void show() {
cout << "已存有信息的学生个数为:" << this->m_StuNum << "\n\n";
for (int i = 0; i < this-