1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void readStudents_andWrite(ifstream &in, ofstream &out, string in_file_name, string out_file_name, Student student[], size_t &index)
{
in.open(in_file_name);
string No, student_id, Last_name, First_name, Gender, DoB;
if (!in.is_open())
{
cout << "Error!\n";
}
else
{
getline(in, No, ',');
getline(in, student_id, ',');
getline(in, Last_name, ',');
getline(in, First_name, ',');
getline(in, Gender, ',');
getline(in, DoB, '\n');
while (getline(in, student[index].no, ','))
{
getline(in, student[index].id, ',');
getline(in, student[index].last_name, ',');
getline(in, student[index].first_name, ',');
getline(in, student[index].gender, ',');
getline(in, student[index++].dob, '\n');
}
in.close();
}
out.open(out_file_name);
if (!out.is_open())
{
cout << "Error!\n";
}
else
{
out << No << "," << student_id << "," << Last_name << "," << First_name << "," << Gender << "," << DoB << endl;
for (int i = 0; i < index; i++)
{
out << student[i].no << " ";
out << student[i].id << " ";
out << student[i].last_name << " ";
out << student[i].first_name << " ";
out << student[i].gender << " ";
out << student[i].dob << endl;
}
out.close();
}
}
|