VS2010 编写的机器人文件以时间命名


#include "stdafx.h"

#include <iostream>

#include <time.h>

#include <stdlib.h>

#include <fstream>

using namespace std;

 

int main(int argc, char* argv[])

{

	time_t currtime = time(NULL);

	tm* p = localtime(&currtime);

	char filename[100] = {0};

 

    sprintf(filename,"D:\\%d%02d%02d%02d%02d%02d.txt",p->tm_year+1900,p->tm_mon+1,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);

 

	ofstream fout2(filename);

	fout2<<"content"<<endl;

	

	return 0;

}

最近写轨迹求解软件,需要将文件以时间命名。在char类型的filename转到CString格式中,是不兼容的,用sprintf可以对字符进行拼合。

猜你喜欢

转载自blog.csdn.net/m0_37756557/article/details/83055528
今日推荐