也可参考 my github blog
time
- 部分函数使用参考
- utc 转日期时间等
inline std::string utc2date(const time_t &rawtime /*unit:s*/)
{
struct tm *tinfo = std::localtime(&rawtime);
char buffer[30];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tinfo);
return std::string(buffer);
}
string
文件IO
- 使用ifstream和getline读取文件内容
- 判断文件夹存在
static bool checkExist(const std::string &path)
{
DIR* dir = opendir(path.c_str());
if(dir) { closedir(dir); return true; }
else if(ENOENT == errno) return false;
}
- 删除文件及文件夹
#include <stdio.h> //delete file
#include <unistd.h> //delete dir
#include <errno.h>
int ret = remove(file_name);
int ret = rmdir("/home/cnd/mod1");
printf("remove err:%s\n", strerror(errno)); //check err