一:C++中%d,%s,%x,%f,%.100f,%的意思
二:c++生成uuid
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
int main(){
boost::uuids::uuid a_uuid = boost::uuids::random_generator()();
string uuid_string = boost::uuids::to_string(a_uuid)
return 0;
}
三:c++获取时间并生成字符串
//添加头文件#include<assert.h>
time_t t = time(0);
char ch[64];
strftime(ch, sizeof(ch), "%Y-%m-%d %H-%M-%S", localtime(&t)); //年-月-日 时-分-秒
四:c++判断文件夹是否存在,不存在则创建文件夹
#include <direct.h>
#include <io>
#include <iostream>
using namespace std;
int main()
{
string folderPath = "E:\\database\\testFolder";
if (0 != access(folderPath.c_str(), 0))
{
// if this folder not exist, create a new one.
mkdir(folderPath.c_str()); // 返回 0 表示创建成功,-1 表示失败
//换成 ::_mkdir ::_access 也行,不知道什么意思
}
return 0;
}
五:c++中的string和char[]的转换
//字符数组转化成string类型
char ch [] = "ABCDEFG";
string str(ch);//也可string str = ch;
或者
char ch [] = "ABCDEFG";
string str;
str = ch;//在原有基础上添加可以用str += ch;
//将string类型转换为字符数组
char buf[10];
string str("ABCDEFG");
length = str.copy(buf, 9);
buf[length] = '\0';
或者
char buf[10];
string str("ABCDEFG");
strcpy(buf, str.c_str());//strncpy(buf, str.c_str(), 10);
参考链接:
https://www.cnblogs.com/shierlou-123/p/12342899.html
https://www.jianshu.com/p/33639aee1ffa
https://blog.csdn.net/u012526003/article/details/52805800
https://blog.csdn.net/sinat_41104353/article/details/83149441