c++一些简单操作

一: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Studying_swz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值