void ImportFileCSV() { Course c; string year, semester, Class, sourcefile; //Input information file text out cout << "Enter academic years: "; cin >> year; cout << "Enter semester: "; cin >> semester; cout << "Enter class: "; cin >> Class; cout << "EXAM SOUCRE FILE: CS162\\Schedule\\19APCS1-Schedule.csv" << endl; cout << "Enter source file: "; cin >> sourcefile; ifstream fin, csvFin; csvFin.open(sourcefile, ios::in); if (!csvFin.is_open()) { cout << "Can not open CSV file to import!!!" << endl; return; } int nCount = 0; //Count elements while (csvFin.good()) { string temp; getline(csvFin, temp, '\n'); nCount++; } csvFin.close(); // Open file to read again and write ofstream fout("CS162\\Schedule\\" + year + "-" + semester + "-Schedule-" + Class + ".txt", ios::out); fin.open(sourcefile, ios::in); fout << nCount - 2 << endl; //-2 because '\n' in line 1 and last line // Ignore the first line string temp; getline(fin, temp, '\n'); // while (fin.good()) { //Read file fin >> c.No; fin.ignore(); getline(fin, c.courseID, ','); getline(fin, c.courseName, ','); getline(fin, c.lecturerUser, ','); getline(fin, c.lecturerName, ','); getline(fin, c.lecturerDegree, ','); fin >> c.lecturerGender; fin.ignore(); fin >> c.startDay.day; fin.ignore(); fin >> c.startDay.month; fin.ignore(); fin >> c.startDay.year; fin.ignore(); fin >> c.endDay.day; fin.ignore(); fin >> c.endDay.month; fin.ignore(); fin >> c.endDay.year; fin.ignore(); fin >> c.Day; fin.ignore(); fin >> c.hourStart.hour; fin.ignore(); fin >> c.hourStart.minute; fin.ignore(); fin >> c.hourEnd.hour; fin.ignore(); fin >> c.hourEnd.minute; fin.ignore(); getline(fin, c.Room, '\n'); //write file fout << c.courseID << endl; fout << c.courseName << endl; fout << c.lecturerUser << endl; fout << c.lecturerName << endl; fout << c.lecturerDegree << endl; fout << c.lecturerGender << endl; fout << c.startDay.year << " " << (c.startDay.month < 10 ? "0" : "") << c.startDay.month << " " << (c.startDay.day < 10 ? "0" : "") << c.startDay.day << endl; fout << c.endDay.year << " " << (c.startDay.month < 10 ? "0" : "") << c.endDay.month << " " << (c.startDay.day < 10 ? "0" : "") << c.endDay.day << endl; fout << c.Day << endl; fout << c.hourStart.hour << " " << (c.hourStart.minute < 10 ? "0" : "") << c.hourStart.minute << endl; fout << c.hourEnd.hour << " " << (c.hourEnd.minute < 10 ? "0" : "") << c.hourEnd.minute << endl; fout << c.Room << endl; } fin.close(); fout.close(); }