小编Chi*_*kar的帖子

在C++中将系统日期和时间作为文件名传递

我想建立一个考勤系统,它将系统日期和时间作为文件的文件名,例如:这是通常的情况.

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头文件来计算时间只是示例.

c++ fstream ctime

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

ctime ×1

fstream ×1