心理

当前位置 /首页/完美生活/心理/列表

c++如何设置时间

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)

}

TAG标签:时间 设置 #