// cl -GX testRead2.cpp // cl -EHsc testRead2.cpp #include #include using namespace std; void main() { char buf[50]; fstream infile("ntou2.txt"); if (!infile) { cout << "無法開啟 ntou2.txt\n"; cout << "Press to continue ...\n"; cin.getline(buf, 50, '\n'); return; } char campusName[50]; infile.getline(campusName, 50, '\n'); cout << "學校名稱: " << campusName << endl; int numberOfColleges; infile >> numberOfColleges; infile.getline(buf, 50, '\n'); int iCol; for (iCol=0; iCol> numberOfDepartments; infile.getline(buf, 50, '\n'); int iDept; for (iDept=0; iDept> numberOfTeachers; infile.getline(buf, 50, '\n'); if (numberOfTeachers == 0) cout << " 無教師資料" << endl; int iTeac; for (iTeac=0; iTeac> numberOfCourses; infile.getline(buf, 50, '\n'); if (numberOfCourses == 0) cout << " 無課程資料" << endl; int iCourse; for (iCourse=0; iCourse> year; infile.getline(buf, 50, '\n'); cout << " 開課年度: " << year << endl; int semester; infile >> semester; infile.getline(buf, 50, '\n'); cout << " 開課學期: " << semester << endl; char teacherName[50]; infile.getline(teacherName, 50, '\n'); cout << " 授課教師: " << teacherName << endl; } } int numberOfInstitutes; infile >> numberOfInstitutes; infile.getline(buf, 50, '\n'); int iInst; for (iInst=0; iInst> numberOfTeachers; infile.getline(buf, 50, '\n'); if (numberOfTeachers == 0) cout << " 無教師資料" << endl; int iTeac; for (iTeac=0; iTeac> numberOfCourses; infile.getline(buf, 50, '\n'); if (numberOfCourses == 0) cout << " 無課程資料" << endl; int iCourse; for (iCourse=0; iCourse> year; infile.getline(buf, 50, '\n'); cout << " 開課年度: " << year << endl; int semester; infile >> semester; infile.getline(buf, 50, '\n'); cout << " 開課學期: " << semester << endl; char teacherName[50]; infile.getline(teacherName, 50, '\n'); cout << " 授課教師: " << teacherName << endl; } } } cout << "Press to continue ...\n"; cin.getline(buf, 50, '\n'); }