我想建立一个考勤系统,它将系统日期和时间作为文件的文件名,例如:这是通常的情况.
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;
}
Run Code Online (Sandbox Code Playgroud)
但我希望系统日期和时间代替example.txt我通过在上面的程序中包含ctime头文件来计算时间只是示例.