システムの日付と時刻をファイルのファイル名として使用する出席システムを作成したかったのは、たとえば、これが通常の方法です。
int main () {
time_t t = time(0); // get time now
struct tm * now = localtime( & t );
cout << (now->tm_year + 1900) << '-'
<< (now->tm_mon + 1) << '-'
<< now->tm_mday
<< endl;
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
しかし、example.txtの代わりにシステムの日付と時刻が必要です。上記のプログラムにctimeヘッダーファイルを含めることで時間を計算しましたが、これは単なる例です。