C++编程便捷口

 

 

获取当前时间

 1 #include <iostream>
 2 #include <ctime>
 3 #include <stdlib.h>
 4 #include <stdio.h>
 5 
 6 using namespace std;
 7 
 8 string  Get_Current_Date();
 9 
10 int main( )
11 {
12     // 将当前日期以 20** - ** - ** 格式输出
13     cout << Get_Current_Date().c_str() << endl;
14 
15     getchar();
16     return 0;
17 }
18 
19 string  Get_Current_Date()
20 {
21     time_t nowtime;  
22     nowtime = time(NULL); //获取日历时间   
23     char tmp[64];   
24     strftime(tmp,sizeof(tmp),"%Y-%m-%d %H:%M:%S",localtime(&nowtime));   
25     return tmp;
26 }

 

 

 

判断文件是否存在

 1 fstream _file;
 2 _file.open(FILENAME,ios::in);
 3 if(!_file)
 4 {
 5  cout<<FILENAME<<"没有被创建";
 6 }
 7 else
 8 {
 9   cout<<FILENAME<<"已经存在";
10 }

 

posted @ 2019-01-22 09:42  Yang_tao  阅读(127)  评论(0编辑  收藏  举报