#include <string> #include <iostream> #include <time.h> #include <fstream> using namespace std; //本函数用于获取当前系统的时间,使用前请传入获取时间的string的引用 void getSystemTime(string & stime){ time_t t = time( 0 ); char tmp[64]; strftime( tmp, sizeof(tmp), "%Y/%m/%d %X ",localtime(&t) ); stime=tmp; } int main(){ string nowtime;//存储获取的系统的时间 //输出起始时间 getSystemTime(nowtime); cout<<nowtime<<endl; //这一步仅仅是为了耗费程序的时间 ofstream fout("tt.txt"); for(long i=0; i<1000*1000; ++i){fout<<i<<endl;} //输出结束时间 getSystemTime(nowtime); cout<<nowtime<<endl; system("pause"); return 0; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <string>
#include <iostream>
#include <time.h>
#include <fstream>
using
namespace
std
;
//本函数用于获取当前系统的时间,使用前请传入获取时间的string的引用
void
getSystemTime
(
string
&
stime
)
{
time
_t
t
=
time
(
0
)
;
char
tmp
[
64
]
;
strftime
(
tmp
,
sizeof
(
tmp
)
,
"%Y/%m/%d %X "
,
localtime
(
&
t
)
)
;
stime
=
tmp
;
}
int
main
(
)
{
string
nowtime
;
//存储获取的系统的时间
//输出起始时间
getSystemTime
(
nowtime
)
;
cout
<<
nowtime
<<
endl
;
//这一步仅仅是为了耗费程序的时间
ofstream
fout
(
"tt.txt"
)
;
for
(
long
i
=
0
;
i
<
1000
*
1000
;
++
i
)
{
fout
<<
i
<<
endl
;
}
//输出结束时间
getSystemTime
(
nowtime
)
;
cout
<<
nowtime
<<
endl
;
system
(
"pause"
)
;
return
0
;
}
|