reading and writeing from a file
int year,month,day,hour,minute,second; ifstream fin; fin . open("time.txt",ios::in); if (fin == NULL){ cout << "file can not be opened\n"; exit(0); } while (!fin.eof()) { fin >> year,month,day,hour,minute,second; cout << year << " / "; if (month < 10) cout << "0"; else cout << ""; cout << month << " / "; if (day < 10) cout << "0"; else cout << ""; cout << day << "\n"; cout << hour << ":"; if (minute < 10) cout << "0"; else cout << ""; cout << minute << ":"; if (second < 10) cout << "0"; else cout << ""; cout << second; if (hour < 12) cout << " AM" << endl; else cout << " PM" << endl; } fin.close();
Join our real-time social learning platform and learn together with your friends!