首页 > 生活美容 > 心理 > c++如何设置时间

c++如何设置时间

   来源:秀美库    阅读: 1.41W 次
字号:

用手机扫描二维码 在手机上继续观看

手机查看
c++如何设置时间

通过第一个参数的修改时间,修改第二个文件参数的修改时间

参考如下:

#include <time.h>

#include <sys/types.h>

#include <sys/stat.h>

#include &ltstdio.h>

#include <iostream>

#include <string>

using namespace std

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

{

if(argc<2)

{

cout<<"No arguments"<<endl

exit(1)

}

string file1,file2

file1=argv[1]

file2=argv[2]

struct stat buf1

struct stat buf2

int result1,result2

//获得文件状态信息

result1 =stat( file1.c_str(), &buf1 )

result2 =stat( file2.c_str(), &buf2 )

//显示文件状态信息

if( result1 != 0 )

perror( "显示文件状态信息出错" )

else

{

cout<<"最后修改日期1:"<<ctime(&_mtime)

}

//显示文件状态信息

if( result1 != 0 )

perror( "显示文件状态信息出错" )

else

{

cout<<"最后修改日期2:"<<ctime(&_mtime)

}

_mtime=_mtime

cout<<"最后修改日期3:"<<ctime(&_mtime)

}

减肥
家居
健康
情感
婚姻
亲子
星座
宠物