c/c++
GreenTeemo
差距使我进步
展开
-
RegexConf:基于正则表达式的配置读取库
github链接:https://github.com/greenteemo/RegexConfRegexConf基于正则表达式的实时加载(读取)配置库使用说明首先在src目录下执行 sh make.sh 编译生产动态库demo目录下执行 sh run.sh 试用,可查看demo/main.cpp了解主要接口使用方法。demo运行如下:RegexConf Version: V0.0.0 (2021-04-13 16:11)##### Test RegexConf #####a原创 2021-04-13 17:21:37 · 196 阅读 · 0 评论 -
[c/c++] d_type判断文件是否为目录无效
背景使用power主机不能使用dirent结构体中的d_type判断文件是否为目录原因分析在readdir的man手册( https://linux.die.net/man/3/readdir)中,提示d_type不被所有的文件系统支持。其目前仅被Btrfs,ext2,ext3,ext4文件系统支持。x86主机ext4文件系统d_type可用于判断文件类型power主机xfs文件系统d_type无法判断文件类型解决方法#include <sys/stat.h>#in原创 2020-11-03 17:57:47 · 1497 阅读 · 0 评论 -
[c/c++] 通过不定参数实现调试输出
不定参数的两种实现方式通过宏__VA_ARGS__实现通过va_list在函数中实现通过宏__VA_ARGS__实现代码#define DebugPrint(format, ...) fprintf(stdout, "[%s][%d] " format, __FILE__, __LIN__, ##__VA_ARGS__)通过va_list在函数中实现代码int DebugPrint(const char *format, ...){ va_list args; va_sta原创 2020-10-14 18:03:16 · 217 阅读 · 0 评论 -
[c/c++] 后缀_t的那些事
含义后缀_t意味着type/typedef(类型),是一种命名规范,类似于全局遍历加前缀g_。那些事不推荐在自己的代码中使用自定义的类型名如果加上后缀_t,则有可能导致与引入库中的类型命名冲突导致错误,因此不建议在自定义的类型名加上后缀_t自定义类型推荐的命名规范自定义类型名加上相关的公司或项目前缀,如qq_int也有人用_type作为后缀,如int_type结合前两项,可以使用qq_int_type主要被定义在头文件stdint.h中在stdint.h文件中,可以看的一些常原创 2020-10-09 16:23:09 · 3481 阅读 · 0 评论 -
[c/c++] i++与++i的区别
主要区别值的区别左值右值区别效率区别实现代码下面以郭炜老师c++课程中的一段代码为例类定义class cDemo{private: int n;public: cDemo(int i) : n(i) {} cDemo& operator++(); // 前置++ cDemo operator++(int); // 后置++};前置++cDemo&...原创 2020-03-31 11:18:32 · 214 阅读 · 0 评论 -
[c/c++][Linux] 时间戳转换为tm,time_t,timeval
refhttps://blog.csdn.net/GreenTeemo/article/details/102586265code#include <stdio.h>#include <time.h>#include <sys/time.h>int main(){ char time[100] = "2020/03/25 11:09:42...原创 2020-03-25 18:27:32 · 3320 阅读 · 1 评论 -
[c/c++] 借助zlib库读取.gz文件内容
文件指针struct gzFile_s { unsigned have; unsigned char *next; z_off64_t pos;};typedef struct gzFile_s *gzFile;打开.gz文件gzFile ZEXPORT gzopen(path, mode) const char *path; const ch...原创 2019-12-24 20:11:49 · 2578 阅读 · 0 评论 -
[c/c++] gcc makefile -D宏定义 -U取消宏定义
前言Makefile中常见到-D,但这其实不是makefile所有的,而是gcc所有的。-D-D namePredefine name as a macro, with definition 1.定义宏,且将其值默认定义为1宏定义gcc -D FOOgcc -DFOO可通过以上两种方式来宏定义FOO,即-D后加空格或不加空格都可以,这两种方式定义,FOO的值默认为1。...原创 2019-12-11 18:03:20 · 4427 阅读 · 1 评论 -
[C/C++]priority_queue构建大顶堆和小顶堆
referencepriority_queue<int, vector<int>, less<int>> max_heap;priority_queue<int, vector<int>, greater<int>> min_heap;原创 2019-12-02 17:28:08 · 814 阅读 · 0 评论 -
[c/c++] 字符数组定义、初始化及赋值后strlen和sizeof的对比
代码#include <stdio.h>#include <string.h>int main(){ char str[20]; printf("char str[20];\nstrlen = %d\nsizeof = %d\nstr = %s\n\n", strlen(str), sizeof(str), str); memset(str, 0, ...原创 2019-10-18 11:15:34 · 226 阅读 · 0 评论 -
[c/c++][Linux] 时间类型操作汇总笔记
Linux下获取微秒级时间ref:https://www.cnblogs.com/fengbohello/p/4153831.html定义#include <sys/time.h>int gettimeofday(struct timeval*tv, struct timezone *tz);其参数tv是保存获取时间结果的结构体,参数tz用于保存时区结果(此处不需要tz,故...原创 2019-10-16 16:08:25 · 262 阅读 · 0 评论 -
[c/c++] 文件指针位置回到文件开头(rewind)及行开头(ftell+fseek)
待读入文件1.greenteemo2.csdn3.blog代码,详细说明见注释#include <stdio.h>#define LENGTH_OF_LINE 1024int main(){ FILE *fp = fopen("file.txt", "r"); // 打开文件 char line[LENGTH_OF_LINE]; ...原创 2019-09-26 16:12:14 · 15447 阅读 · 0 评论 -
[c/c++] 如何遍历char**
#include <iostream>using namespace std;int main(){ // 初始化 char ** char *temp[2] = {"Raptors", "Warriors"}; char **x = temp; // 遍历 char** for(int i = 0; x &&...原创 2019-06-03 16:43:42 · 7614 阅读 · 0 评论