2020-12-10:用C++写一个简单的记录程序
用C++写一个简单的记录程序#define WINVER 0x0A00//run enviroment is win10#include<fstream>#include<iostream>#include<afxwin.h>//for messagebox#include<time.h>#include<io.h>//for acces
·
用C++写一个简单的记录程序
#define WINVER 0x0A00 //run enviroment is win10
#include<fstream>
#include<iostream>
#include<afxwin.h> //for messagebox
#include<time.h>
#include<io.h> //for access()
using namespace std;
char path[] = "D:/log.txt";
bool check()
{
if(access(path, 0) == 0)
{
//cout<<path<<": 文件存在"<<endl;
return true;
}
else
{
return false;
}
}
void main(int argc, char* argv[])
{
time_t rawtime;
struct tm timeinf;
time(&rawtime);
localtime_s(&timeinf,&rawtime);
if(argc == 2)
{
cout<<"argv[1]: "<<argv[1]<<endl;
if(!check())
{
fstream ff(path, ios::trunc | ios::out);
ff.close();
}
fstream f1(path, ios::app);
f1<<timeinf.tm_year +1900<< "-" << timeinf.tm_mon +1<< "-" << timeinf.tm_mday;
f1<< " " <<timeinf.tm_hour << ":" << timeinf.tm_min << ":" << timeinf.tm_sec<<"\t=> ";
f1<<argv[1]<<endl;
f1.close();
}
else
{
MessageBoxA(NULL, "一次只能输入一个数据", "", MB_OK);
}
}
编译后设置一下环境变量,然后就可以通过win+r快速运行这个程序了。
更多推荐
已为社区贡献1条内容
所有评论(0)