![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++编程
少言才不会咸
这个作者很懒,什么都没留下…
展开
-
ev++ 头文件
ev++封装转载 2022-09-13 15:50:55 · 271 阅读 · 0 评论 -
c++模板获取函数签名
c++模板获取函数签名。原创 2022-07-24 18:16:32 · 512 阅读 · 0 评论 -
利用模版将多enum转为BitSet
#include <bitset>#include <string>#include <type_traits>#define SetBit(x) (0x1u << x)enum Test : uint32_t { kNum0 = SetBit(0), kNum1 = SetBit(1), kNum2 = SetBit(2), kNum3 = SetBit(3), kNum4 = SetBit(4),};struct Ma原创 2021-03-10 23:58:54 · 187 阅读 · 0 评论 -
通过模板实现可迭代cursor类
#include <mutex>#include <queue>#include <memory>#include <string>#include <iostream>#include <memory>#include <condition_variable>#include <stdio.h>#include <array>#include <vector>#inc原创 2021-03-05 00:29:41 · 193 阅读 · 1 评论 -
类型擦除示例
#include <mutex>#include <queue>#include <memory>#include <string>#include <iostream>#include <memory>#include <condition_variable>#define DBG_LOG(format, ...) \ printf("[%d:%s:%d]" format ", this:%p\n"原创 2021-02-24 23:23:41 · 107 阅读 · 0 评论 -
hierarchical mutex
class hierarchical_mutex{ std::mutex internal_mutex; unsigned long const hierarchy_value; unsigned long previous_hierarchy_value; static thread_local unsigned long this_thread_hierarchy_value; // 1 void check_for_hierarchy_violation()翻译 2020-12-21 15:50:56 · 185 阅读 · 0 评论 -
实现c++ 不可继承类:FinallyClass
#include <iostream>template<typename T>class MakeFinally {private: MakeFinally() {}//只有MakeFinally的友类才可以构造MakeFinally ~MakeFinally() {} friend T;};class MyClass : public virtual MakeFinally<MyClass> {public: void转载 2020-11-02 21:30:01 · 168 阅读 · 1 评论 -
模版检查类中是否有某个成员函数
//例子1template<typename T>struct has_no_destroy{ template <typename C> static char test(decltype(&C::no_destroy)); template <typename C> static int32_t test(...); const static bool value = sizeof(test<T>(0)) == 1;}; /转载 2020-08-04 21:01:12 · 381 阅读 · 0 评论 -
std::enable_if example
#include <iostream>#include <type_traits>// 1. the return type (bool) is only valid if T is an integral type:template <class T>typename std::enable_if<std::is_integral<T&g...原创 2020-04-13 18:13:13 · 199 阅读 · 0 评论 -
sha1sum
#include "openssl/sha.h"#include "openssl/crypto.h"#include <iostream>#include <sstream>#include <fstream>using namespace std;void sha1sum(const char *body, const int len, co...原创 2020-01-03 19:42:42 · 285 阅读 · 0 评论 -
日志打印文件名
template<int N>inline const char * CompileTimeGetFileName(const char(&arr)[N]){ //int size_ = N - 1; const char * filename = arr; const char* slash = strrchr(arr, '/'); if ...原创 2019-12-13 18:17:29 · 247 阅读 · 0 评论 -
基于Linux的Tcp端口扫描器的实现
【代码】基于Linux的Tcp端口扫描器的实现。原创 2017-06-14 21:02:51 · 1087 阅读 · 0 评论 -
c++11使用atomic多线程同步3种方法
// 使用CAS实现多线程无锁访问共享变量,达到线程同步# include <iostream># include <thread># include <mutex># include <atomic>using namespace std;std::atomic<int> var(0);void add() { ...原创 2019-04-12 11:53:59 · 1862 阅读 · 0 评论 -
使用指针访问虚函数表
#include <iostream>#include <functional>using namespace std;class Base { public: int a; virtual void g() { cout << "Base::g" << endl; } virtual...原创 2019-04-11 23:01:21 · 485 阅读 · 0 评论 -
结构体中包裹变量实现改值
typedef struct _t{ int** p;}T;void test(int **p){ int** t = (int **)realloc(p,80000); p = t; cout << p << endl;}void test2(T *n){ int** t = (int **)realloc(n-...原创 2019-03-13 18:40:37 · 170 阅读 · 0 评论 -
const、static、const static、static const关键字的初始化
#include &amp;amp;lt;iostream&amp;amp;gt;#include &amp;amp;lt;algorithm&amp;amp;gt;using namespace std;/* * 规则: * 1、static 变量:声明在类中,定义赋值在类外 * 2、const 变量:由于要进入符号表,在类中声明的时候就得赋值定义 * 3、const + static:在类外赋值的时候去掉static关键字原创 2019-03-03 10:51:31 · 450 阅读 · 0 评论 -
ip转2进制
#include <iostream>#include <bitset>#include <string>#include <sstream>#include <cstdlib>#define METHODusing namespace std;string ip2bin (string addr){ istri...原创 2019-02-22 14:56:45 · 704 阅读 · 0 评论 -
使用C语言内嵌汇编实现CAS
#include <stdio.h>#include <unistd.h>#include <pthread.h>#include <stdlib.h>#define MODE 4pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;/*本质就是CPU提供了一个叫做 CPMXCHG 的指...原创 2019-04-15 16:18:51 · 2157 阅读 · 0 评论 -
使用CAS实现单例模式
#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <pthread.h>long CAS(volatile unsigned long **addr, long old, long *new){ /* https://...原创 2019-04-15 18:02:32 · 1097 阅读 · 0 评论 -
玩转c++模板模板参数
#include <iostream>#include <list>#include <vector>using namespace std;#if 1//template <typename T, template<typename E, typename Alloc = std::allocator<E>> clas...原创 2019-04-28 16:54:11 · 553 阅读 · 1 评论 -
STL list sort
#include <cstdio>#include <list>#include <iostream>using namespace std;typedef list<int> IList;void print(const IList &list){ IList::const_iterator ite = list....转载 2019-05-04 21:55:53 · 134 阅读 · 0 评论 -
c++11遍历打印tuple(借助模版参数)
#include <tuple>#include <iostream>using namespace std;// 由于std::get<size_t>(t)的语法中是size_t必须在编译的时候确定,所以无法传左值。// 借助模板中的可变模板参数递归实现template<typename Tuple, size_t N>struct ...转载 2019-05-07 21:52:03 · 1101 阅读 · 1 评论 -
实现C++字符串的spilt
std::string mySplit(std::string src, uint8_t field ,char delim=' '){ std::stringstream ss(src); std::string target; for(int i=0; i < field+1; ++i) std::getline(ss, target, delim); return ...原创 2019-05-24 16:33:16 · 485 阅读 · 0 评论 -
多个单例对象,析构顺序模拟
#include <iostream>#include <unistd.h>using namespace std;struct StaticMember{public: int age = 6; StaticMember() { std::cout << "StaticMember()" << s...原创 2019-07-18 11:31:50 · 460 阅读 · 0 评论 -
weak_ptr使用的几个实例
#include <iostream>#include <memory>#include <algorithm>#include <string>#include <vector>#include <memory>/////////////////////////////////////////////////...转载 2019-08-08 19:20:51 · 292 阅读 · 0 评论 -
C语言要点
10月27日总结导出dll模块 dll: _declexport(dllexport) void goA() { }常用windows函数MessageBoxA(0,”网络故障,请重新登录”,”,QQ故障”,0); //代表系统弹出 //内容 //标题 //对话框类型ShellExecuteA(0,”open”,”notepad”,0,0,0); //代表系统弹出 //ope原创 2016-10-27 19:14:15 · 211 阅读 · 0 评论 -
C语言开发CGI
//get.c#include <stdio.h>#include <stdlib.h>int main(void){ char *data; char a[10],b[10]; printf("Content-Type:text/html\n\n"); printf("<HTML>\n"); printf("<转载 2017-03-23 16:17:34 · 368 阅读 · 0 评论 -
C语言Scanf函数特殊用法
原文地址](http://blog.csdn.net/qingkong8832/article/details/6667701%20%E5%8E%9F%E6%96%87%E5%9C%B0%E5%9D%80)scanf 语法: #include <stdio.h>int scanf( const char *format, ... );类似函数有int scanf(const char *f转载 2017-03-20 21:44:20 · 794 阅读 · 0 评论 -
SOCKET_PRGM--Lin/Win条件编译版本
//pub.h#ifndef _H_PUB_H_#define _H_PUB_H_#ifdef WIN#include <WinSock2.h>#else#include <stdlib.h>#include <unistd.h>#include <sys/socket.h>#include <arpa/inet.h>#include <errno.h>#include <str转载 2017-03-09 10:27:20 · 341 阅读 · 0 评论 -
C字符串操作:字符串反转
#include "stdio.h"#include "stdlib.h"#include "string.h"void main(){ char c; //错误写法,指针为常量char *str = "abcdefg" char str[] = "abcdefg"; int len = strlen(str); char *p1 = str;原创 2016-10-28 19:35:40 · 242 阅读 · 0 评论 -
C字符串操作:两头堵实现trim()
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>//一般情况下不要修改输入的内存块的值int trimSpace_ok(char *mybuf, char *outbuf){ int Count = 0; int i = 0, j = 0; char *p = mybu原创 2016-10-28 19:21:42 · 255 阅读 · 0 评论 -
C字符串操作:查找字符串函数strstr()
#include <stdio.h>#include <stdlib.h>#include <string.h>void main (){ char *sub="abcd"; char *p="abcd1111abcd2222abcd"; int count=0; do { p=strstr(p,sub); if(p!=N原创 2016-10-27 18:38:08 · 2050 阅读 · 0 评论 -
关于c/c++中的static
#include "iostream"using namespace std;/*-------Begin----------C语言部分-------Begin----------*///c语言中的static两种用法://1、用于变量,知道程序结束才释放//2、用于函数,限制在本.c文件中不能被外界调用//状态保留//用static修饰变量void GetStatic(){原创 2016-11-08 21:43:13 · 202 阅读 · 0 评论 -
New/Delete和Malloc/Free的对比
#include "iostream"using namespace std;//1 new/delete(操作符)作用手工分配内存(heap上) malloc/free(函数)//2 new/delete int 基础类型//3 new/delete 数组//4 new/delete类//指针做函数参数class Test1{public: Test1(int a, int原创 2016-11-08 21:42:03 · 173 阅读 · 0 评论 -
C++复制构造函数应用场景
class A{ private: int a; public: A(int m_a){ a = m_a ;} A(const A & Obj){ a = Obj.a; } ...}A fun1(){ A OBJ(3); //会创建匿名对象 return OBJ;}void fun2(A OBJ)原创 2016-11-07 15:49:10 · 357 阅读 · 0 评论 -
void的使用和规则
void的字面意思是“无类型”,void 则为“无类型指针”,void 可以指向任何类型的数据。void几乎只有“注释”和限制程序的作用,定义一个void变量没有意义,不妨试着定义: void a; 这行语句编译时会出错,提示“illegal use of type ‘void’”。不过,即使void a的编译不会出错,它也没有任何实际意义。 void真正发挥的作用在于: (转载 2016-10-26 17:25:11 · 403 阅读 · 0 评论 -
单词首字母转换大小写
#include <iostream>using namespace std;int main(){ char sentence[50]="i am student, you are teacher."; char pre=' '; for(int i=0;i<50;i++) { if(sentence[i] != ' ' && pre == ' ')原创 2016-11-05 20:11:41 · 407 阅读 · 0 评论 -
c++初始化构造、初始化调用
#include "iostream"using namespace std;//隐式 或 显示 构造函数 析构函数class Test{public: //初始化一:有参构造函数 Test(int a) { m_a = a; } //初始化二:无参数构造函数 Test() { m_a = 0; }原创 2016-11-05 14:50:42 · 248 阅读 · 0 评论 -
inline和override的注意点
c++中对inline的限制: 1、不能存在任何形式的循环语句 2、不能存在过多的条件判断语句 3、函数体不能过于庞大 4、不能对函数进行取址操作 5、函数内联声明必须在调用语句之前c++判断override标准: 1、参数个数不同 2、参数类型不同 3、参数顺序不同 PS:返回值类型不是重载的判断标准原创 2016-11-05 13:44:23 · 431 阅读 · 0 评论 -
代码在内存中的分布
栈区(stack):由编译器自动分配释放,存放函数的参数值,局部变量的值等。堆区(heap):一般由程序员分配释放(动态内存申请与释放),若程序员不释放,程序结束时可能由操作系统回收。全局区(静态区)(static):全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另一块区域,该区域在程序结束后由操作系统释放。常量区:字符串常原创 2016-10-25 22:22:32 · 543 阅读 · 0 评论