
c++
时间溜走了
学无止境
展开
-
OpenSSL中base64编解码使用
/** *由于2进制有一些特殊的字符,在传输的过程传给对端对面解析乱码问题 *\0也是特使字符在传输的过程中读取的时候遇到\0系统认为是结束字符所以导致数据不完整 *含有中文的数据写进数据库数据库存储也会乱码 读取出去也会乱码 *为了解决了以上的问题我们引用了base64进行编码,生成二进制的时候 存储或者传输的时候我们先将他们base64转码之后在进行存储或者传输 *openssl 里面封装bio对象的 可以对base64操作 */#include<openssl/buffer.h>#in原创 2021-07-11 16:05:14 · 1202 阅读 · 0 评论 -
Tcp流式传输解决粘包和少包的方案
tcp是流式传输协议,接收端和发送端的 收发时间延时,此时会出现粘包现象。比如:再不考虑内核双向缓冲区的延时发送问题,客户端假设1s 发送100k,循环发,服务器每2s收一次数据,此时服务器收到了200k,出现了消息粘包,服务器也不知道客户端的消息分组情况,所以我们需要和客户端协商一个解决方案,类型tcp底层封装思想一下定义为 消息头和消息体:下面伪代码展示一下:发送端:void sendMsg(int fd, char* sendData){ /*这里的sendData数据体他是字符串形式的原创 2021-07-02 11:19:36 · 502 阅读 · 0 评论 -
libevent网络框架学习
//client.c#include<stdlib.h>#include<stdio.h>#include<unistd.h>#include<string.h>#include<fcntl.h>#include<sys/stat.h>#include<event2/event.h>#include<event2/bufferevent.h>char buf[1024];void read.原创 2021-06-12 17:25:48 · 244 阅读 · 1 评论 -
c++ 加入信号量控制线程的终止和退出
信号量的实现#ifndef _CELL_SEMAPHORE_HPP_#define _CELL_SEMAPHORE_HPP_#include<chrono>#include<thread>#include<condition_variable>//信号量class CELLSemaphore{public: //阻塞当前线程 void wait() { std::unique_lock<std::mutex> lock(_m原创 2020-06-18 00:04:41 · 1527 阅读 · 1 评论 -
C++ 初识window下 IOCP网络模式
window下 IOCP网络模式#define WIN32_LEAN_AND_MEAN#include<windows.h>#include<WinSock2.h>#pragma comment(lib,"ws2_32.lib")#include<mswsock.h>#pragma comment(lib,"Mswsock.lib")#include<stdio.h>#define nClient 10enum IO_TYPE{原创 2020-06-17 21:38:59 · 508 阅读 · 0 评论 -
C++中static关键字作用总结
1.先来介绍它的第一条也是最重要的一条:隐藏。(static函数,static变量均可)当同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性。举例来说明。同时编译两个源文件,一个是a.c,另一个是main.c。//a.cchar a = 'A'; // global variablevoid msg(){ printf("Hello\n");}//main.cint main(){ extern char a; // extern ...转载 2020-06-17 12:01:11 · 232 阅读 · 0 评论 -
c++ 纯虚函数和虚函数重写调用
纯虚函数和虚函数重写调用class parent{public: parent(int a, int b) { this->a = a; this->b = b; cout << "我是爸爸构造函数" << endl; } void printfP() { dotest(); } virtual void dotest() { cout << "parent:dotest()" << endl;.原创 2020-06-17 11:43:13 · 1260 阅读 · 0 评论 -
C++ 继承 之 构造析构顺序
继承 之 构造析构顺序#include<iostream>using namespace std;class parent{public: parent(int a, int b) { this->a = a; this->b = b; cout << "我是爸爸构造函数" << endl; } void printfP() { dotest(); } virtual void dotest() { cout原创 2020-06-17 11:36:45 · 918 阅读 · 1 评论 -
初识Linux下epoll网络通信
#ifndef _WIN32#include<unistd.h> //uni std#include<arpa/inet.h>#include<string.h>#include<sys/epoll.h>#endif#define SOCKET int#define INVALID_SOCKET (SOCKET)(~0)#define SOCKET_ERROR (-1)#include<stdio.h&.原创 2020-06-16 19:07:55 · 203 阅读 · 0 评论 -
strchr函数用法-查找切割
原型:char *strchr(const char *s, int c);头文件:#include <string.h>描述:用于查找字符#include <iostream>#include <string.h>using namespace std;int main(){ char str[] = "Hello World!"; char* p1 = strchr(str, 'r'); if (p1) {...转载 2020-06-12 16:46:10 · 390 阅读 · 0 评论 -
c++ 消息字节流数据读和写
#ifndef _CELL_STREAM_HPP_#define _CELL_STREAM_HPP_#include <cstdint>class CELLStream{public: //创建数据块 (写消息) CELLStream(int nSize = 1024) { _nSize = nSize; _pBuff = new char[_nSize]; _bDelete = true; } ...原创 2020-06-10 21:04:01 · 2547 阅读 · 0 评论 -
c++简易日志文件系统
#ifndef _CELL_LOG_HPP_#define _CELL_LOG_HPP_#include"CELL.hpp"#include"CELLTask.hpp"#include<ctime>class CELLLog{ //Info //Debug //Warring //Errorpublic: CELLLog() { _taskServer.Start(); } ~CELLLog()...原创 2020-06-08 19:35:40 · 266 阅读 · 0 评论 -
c++跨平台 计时器
#ifndef _CELLTimestamp_hpp_#define _CELLTimestamp_hpp_//#include <windows.h>#include<chrono>using namespace std::chrono;class CELLTime{public: //获取当前时间戳 (毫秒) static time_t getNowInMilliSec() { return duration_cast&l...原创 2020-06-05 19:25:09 · 478 阅读 · 0 评论 -
c++ 对象池的实现
#ifndef _CELLObjectPool_hpp_#define _CELLObjectPool_hpp_#include<stdlib.h>#include<assert.h>#include<mutex>#ifdef _DEBUG#ifndef xPrintf#include<stdio.h>#define xPrintf(...) printf(__VA_ARGS__)#endif#else#ifndef xPrintf#原创 2020-06-02 10:28:11 · 279 阅读 · 0 评论 -
C++ 内存池实现 并管理内存池(支持多线程)
Alloctor.h:#ifndef _ALLOCTOR_H_#define _ALLOCTOR_H_void* operator new(size_t size);void operator delete(void* p);void* operator new[](size_t size);void operator delete[](void* p);void* mem_alloc(size_t size);void mem_free(void* p);#endif.原创 2020-06-01 11:35:25 · 829 阅读 · 0 评论 -
cocos2dx-Text 详细
local text = ccui.Text:create(content, "font/sysfont.ttf", 18)text:setPosition(pos) --设置位置text:setColor(color) --设置颜色text:setFontSize(size) --设置字体大小text:setTextHorizontalAlignment(alignment ...原创 2020-01-16 17:16:14 · 1447 阅读 · 0 评论 -
C++11提供了创建匿名函数的能力,叫做Lamda函数
C++11提供了创建匿名函数的能力,叫做Lamda函数:std::function callback = nullptr;如果其他地方调用了if (_callback) _callback(&info);在他应用地方就是回调触发该事件:gameInfo.callback = [this](Mahjong::Mahjong_UserResponseInfo* respon原创 2017-09-30 11:50:58 · 353 阅读 · 0 评论 -
cocos2dx定时器的用法
cocos2dx中有三种定时器:schedule,scheduleUpdate,scheduleOnce。1. schedule 的用法: 先定义一个函数 void updatetime(float ft);//开启自定义定时器schedule(schedule_selector(HelloWorld::updatetime), 1.0); 每间隔1s调用一次updatetim原创 2017-10-11 11:20:28 · 405 阅读 · 0 评论 -
下载图片放到纹理缓存中
#include "GameMingpian.h"#include "LibHNLobby/HNLobbyExport.h"static const char* CREATE_NAME_INFO = "platform/setCareateNameInfo/createInfoName.csb";static const char* MING_PIAN = "platform/setCar原创 2017-11-10 18:19:44 · 382 阅读 · 0 评论 -
C++ STL replace()函数常用用法详解
replace算法: replace函数包含于头文件#include中。 泛型算法replace把队列中与给定值相等的所有值替换为另一个值,整个队列都被扫描,即此算法的各个版本都在 线性时间内执行———其复杂度为O(n)。 即replace的执行要遍历由区间[frist,last)限定的转载 2017-10-17 10:52:10 · 833 阅读 · 0 评论 -
c++调用lua,lua调用c++
1首先在官网下载lua的库 将lua编译成动态库创建工程 引用lua的动态库和工程项目的配置信息extern "C" //注释:lua都是以c语言编译的,而当前项目是c++项目所以需要声明下此时是c语言的{#include #include #include };#include #include using namespace std;int cTestRe(lua原创 2017-11-12 13:07:41 · 778 阅读 · 0 评论 -
c++和MFC 交互通过lua脚本实例
width = 600height = 400local pathdlg =1000local contendlg = 1002--alert(getText(1000))function Load() local path = getText(pathdlg); --alert(txt); local inp = io.open(path, "rb") //去读原创 2017-11-12 13:12:37 · 2034 阅读 · 0 评论 -
C++操作MYSQL数据库
1.安装mysql略2.建立C++控制台程序,新建CPP源文件,如:sqlconn.cpp3.在工程项目中属性->c/C++->常规->附加包含目录中添加mysql安装目录中的MySQL\MySQL\MySQL Server 5.7\include 4.添加库目录 5.添加依赖项” libmysql.lib” 6.将运行平台改为X64(这步很重要,不然编译时会报错 )7.在源文...转载 2018-04-16 16:56:00 · 10727 阅读 · 0 评论 -
字符串过滤C++实现
#include<iostream> using namespace std; void stringFilter(const char*pInputStr,long llnputLen,char*pOutputStr) { int a[26]; for (int j=0;j<26;j++) { a[j]=0; } ...转载 2018-04-16 19:24:14 · 2974 阅读 · 1 评论 -
实战c++中的vector系列--对vector<自定义类>使用std::find 和 std::find_if 算法
之前博客讲了一些关于std::find和std::find_ if的一些用法,但是没有讲述对于vector中存储的是自定义的类,那么怎么样使用std::find和std::find_if进行查找呢?先定义一个类:class Item{private: std::string m_ItemId; int m_Price; int m_Count;publi转载 2017-09-07 14:35:30 · 2349 阅读 · 0 评论