請指點:代碼如下:#include <io.h>#include <sys/stat.h> //以上兩個頭文件,用于調用_creat創建文件#include <ctime>#include<iostream>#include<fstream>#include<string>using namespace std;void Backup(){//備份文件,文件名為備份時間const char *file_format = ".txt"; //文件格式time_t t = time(0);char tmp[25];strftime( tmp, sizeof(tmp), "%Y/%m/%d-%X",localtime(&t) );const char *backup_file_name = strcat(tmp,file_format);ofstream backup_file; //輸出文件流backup_file.open(backup_file_name);if(!backup_file){cout << "Can not open Backup file!" << endl;}backup_file << 12345 << " " << "Gosen" << " " << endl;backup_file.close();}是因為我的文件名不符合windows的文件名命名規范。。有斜杠“/”。。。所以創建不成功。。。
3 回答
- 3 回答
- 0 關注
- 168 瀏覽
添加回答
舉報
0/150
提交
取消