![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
photon_wa
这个作者很懒,什么都没留下…
展开
-
【无标题】
用C++实现一个并发编程阻塞队列BlockingQueue原创 2024-06-28 13:55:11 · 206 阅读 · 0 评论 -
带重连功能的websocket client
【代码】使用WebSocket++/websocketpp的带重连功能的websocket client。原创 2023-06-20 09:34:45 · 808 阅读 · 0 评论 -
boost posix_time时区问题
boost::posix_time::microsec_clock::universal_time()获取格林威治时间。使用boost::posix_time::microsec_clock::local_time()获取本地时间。boost::aiso::timer的expries_at()返回的格林威治时间。有时候获取到格林威治时间时间,想输出为本地时间,原创 2023-04-14 14:36:53 · 287 阅读 · 0 评论 -
MySQL Connector/C++使用过程中的问题
Linux环境下,使用mysql connector cpp的时候,链接的时候报错:类似于上面这种,总之是libmysqlcppconn.so使用的libssl与现在开发环境其他库(如boost,rbmq等)使用的libssl版本不一样。原创 2023-03-09 17:37:52 · 961 阅读 · 0 评论 -
ulimit设置coredump文件大小
在linux系统中,如果coredump文件大小设为0,即使程序发生了core dump(segment fault)也没有core文件产生。原创 2022-11-15 18:21:25 · 1689 阅读 · 0 评论 -
使用boost asio raw socket创建第2层/ ethernet套接字(在C ++中)
// #include <boost/asio/detail/config.hpp>// #include <boost/asio/detail/socket_types.hpp>// #include <boost/asio/basic_raw_socket.hpp>// #include <boost/asio/ip/basic_endpoint.hpp>// #include <boost/asio/ip/basic_resolver.hp原创 2022-05-11 22:06:46 · 402 阅读 · 0 评论 -
Linux使用occi访问Oracle数据库
何为occi?occi 是Oracle C++ Call Interface的缩写,官网为:https://docs.oracle.com/en/database/oracle/oracle-database/18/adobj/oracle-c-cpp-call-interface-odci.html安装occi下载地址:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.ht..原创 2022-04-13 15:14:31 · 1802 阅读 · 0 评论 -
Linux使用Poco库访问数据库
安装Poco库https://github.com/pocoproject/poco/https://docs.pocoproject.org/current/注意依赖库,如openssl 等依赖库提前安装访问MySQL需要mysqlclienthttps://blog.csdn.net/wanghualin033/article/details/108709474访问Oracle Poco::Data::ODBC::Connector::registerConnector();.原创 2022-04-13 14:59:42 · 2008 阅读 · 0 评论 -
Boost.Asio 网络编程翻译
https://m.w3cschool.cn/nlzbw/nlzbw-mr5h25y6.html转载 2021-12-28 13:58:02 · 95 阅读 · 0 评论 -
从pcap文件中读数据并组播
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <arpa/inet.h>#include <netinet/in.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/socket.h>#include <原创 2021-09-03 09:49:22 · 293 阅读 · 0 评论 -
CAS C++实现无锁栈
cppreferenc上实现了一个无锁栈,只实现了push, 这里补充完整:#include <atomic>#include <iostream>using namespace std;template<typename T>struct Node{ T data; Node* next; Node(const T& data_) : data(data_) {}};template<typename T>原创 2021-08-24 10:28:16 · 468 阅读 · 2 评论 -
局部作用域内的类不能有必须在类外初始化的成员变量
以前讲过类的静态成员变量初始化问题: 非static, static constexpr, static const int/enum 类型的成员变量可以在类内初始化, 其他必须在类外初始化。另外再提一个累的静态成员变量的限制: 局部作用域内的类不能有必须在类外初始化的成员变量。int main(){ struct S { int x; static int y; bool f; }; int S::y = 0; //类外初始化原创 2021-03-08 20:51:43 · 103 阅读 · 0 评论 -
聚合类的列表初始化
https://stackoverflow.com/questions/18184096/c11-struct-initialization-compilation-errorhttps://stackoverflow.com/questions/8162994/why-arent-static-data-members-allowed-in-local-classes原创 2021-03-08 20:30:18 · 264 阅读 · 0 评论 -
C++十六进制字符流转二进制
python: bytes.fromhex()https://tweex.net/post/c-anything-tofrom-a-hex-string/原创 2020-12-29 19:01:56 · 974 阅读 · 0 评论 -
C++多线程与信号signal
https://www.xspdf.com/resolution/55857746.htmltest66-sigaction.cpp原创 2020-12-17 20:03:52 · 7210 阅读 · 0 评论 -
C++多线程与异常
每个线程有自己的栈空间, 不同线程之间的异常不能传递, 一般每个线程handle自己的异常, 如果线程发生异常没有catch, 会导致线程终止,进而进程终止, 例如。#include <thread>#include <chrono>#include <stdexcept>#include <iostream>void threadRun(){ int num = 5; while( num-- ) { std::原创 2020-12-15 20:01:46 · 2506 阅读 · 0 评论 -
C++异常处理Exception注意事项
C++异常处理1. 异常Exception2. 什么时候使用异常3. 以引用方式捕获异常4. 构造函数和析构函数1. 异常Exception抛出异常:throw some_exception();捕获异常: try { f(); // ... } catch (std::exception& e) { // ...code that handles the error... }2. 什么时候使用异常异常通常发生于运行期间,如原创 2020-12-04 20:40:01 · 476 阅读 · 0 评论 -
zlib压缩的Python,C++简单用法
hex9=bytes.fromhex(‘789c6d’)c9=zlib.decompress(hex9)hh = zlib.compress(b)https://stackoverflow.com/questions/63005126/how-to-deal-with-array-allocating-in-decompressionhttps://github.com/ebiggers/libdeflate/blob/master/lib/zlib_compress.c原创 2020-11-24 19:55:05 · 1216 阅读 · 1 评论 -
C++迭代器分类及iterator_traits
https://www.geeksforgeeks.org/introduction-iterators-c/https://en.cppreference.com/w/cpp/iterator/iterator_traits原创 2020-10-13 21:47:16 · 390 阅读 · 0 评论 -
C++跨平台开发Linux&Windows
C++ linux/MacOS环境开发和windows环境开发感觉是两个世界,公司招聘C++程序员的时候都会强调是哪一个平台。当然C++开发的区分不止于平台,还有前端后端,不同业务的区别。本文以有限的水平记录一下跨平台开发一点小经验。在Linux环境中我们常用gcc/g++编译器,大的项目会用到makefile, scons等编译工具, linux有其独有的库,如sys/socket., unistd.h等。在Windows环境开发一般就是用Visual Studio编译。C++是编译型语言,不像Ja原创 2020-08-12 20:13:50 · 1348 阅读 · 0 评论 -
C++ const与函数重载
Ref:https://www.geeksforgeeks.org/function-overloading-in-c/?ref=lbp原创 2020-07-15 21:02:12 · 412 阅读 · 0 评论 -
接收多客户链接的TCP Server: 使用多线程或select方法
1. 使用多线程方法:#include<stdio.h>#include<stdlib.h>#include<sys/socket.h>#include<netinet/in.h>#include<string.h>#include <arpa/inet.h>#include <fcntl.h> // for open#include <unistd.h> // for close#includ原创 2020-07-13 18:29:09 · 417 阅读 · 0 评论 -
C++ 线程池 threadpool
发现一个比较好的讲threadpool的blog, 如下:https://www.cnblogs.com/lzpong/p/6397997.html#autoid-0-0-0https://www.jianshu.com/p/eec63026f8d0转载 2020-07-09 11:27:29 · 328 阅读 · 0 评论 -
Lua学习笔记(四)
Lua 与 C++ 协同编程一般是使用lua作为辅助脚本,程序复杂参数配置,处理一些自定义类型, 如:https://rubenlaguna.com/post/2012-11-26-first-steps-in-lua-c+±integration/https://rubenlaguna.com/post/2012-12-09-accessing-cpp-objects-from-lua/而使用luabind可以做到:luabind导出C++类到Lualuabind读取lua脚本中的变量..原创 2020-06-04 21:09:26 · 104 阅读 · 0 评论 -
google-test gtest示例
gtest原创 2020-07-20 14:47:39 · 211 阅读 · 0 评论 -
libpcap 网络数据包捕获, Raw Socket
https://blog.csdn.net/htttw/article/details/7521053https://www.cnblogs.com/coder2012/archive/2013/04/13/3012390.html原创 2020-07-23 19:18:15 · 442 阅读 · 0 评论 -
C++ reflection/反射
1. 先看一下什么叫reflectonwiki上的定义: In computer science, reflection is the ability of a process to examine, introspect, and modify its own structure and behavior.简单地说,就是可以通过名字调用函数,访问对象。而我们有一个对象,可以反推出其类型、成员/方法、成员/方法的类型。很多编程语言都与该特性,如Java、PythonMethod metho原创 2020-05-13 20:20:29 · 4212 阅读 · 0 评论 -
GCC链接库
GCC 静态链接库的顺序很重要GCC 有多个链接库时,可以指定特定链接库原创 2020-04-28 10:17:26 · 562 阅读 · 0 评论 -
命名空间和参数依赖查找--重载操作符operator遇到的问题
http://www.gotw.ca/publications/mill08.htm原创 2020-04-17 19:30:36 · 779 阅读 · 0 评论 -
std::locale设置不当导致异常std::bad_cast
std::locale 区域一般和变量类型,输出方式有关查看和修改locale可以通过如下方式:std::locale loc(std::locale(), new std::ctype<char>);std::locale::global( std::locale("") );std::cout << "The default locale is " ...原创 2020-04-16 20:02:11 · 1178 阅读 · 0 评论 -
LD_PRELOAD + dlsym
https://www.cnblogs.com/saolv/p/9761371.htmlhttps://www.jianshu.com/p/72cc08405a5a原创 2020-03-13 18:31:20 · 1114 阅读 · 0 评论 -
Linux 绑核 cpupin 相关
https://blog.csdn.net/photon222/article/details/88954356http://man7.org/linux/man-pages/man2/sched_setaffinity.2.htmlhttp://man7.org/linux/man-pages/man3/pthread_setaffinity_np.3.htmlhttps://www...原创 2020-03-11 18:24:19 · 829 阅读 · 0 评论 -
std::ifstream::readsome和std::ifstream::read的区别
std::ifstream::readsome的原型如下,可以返回实际读到的字节数量,但是不会把eofbit置1,所以不能直接调用eof判断是否到文件尾streamsize readsome (char* s, streamsize n);std::ifstream::read原型如下,会置eof, 但没法直接得到实际读取字节数istream& read (char* s,...原创 2020-02-28 16:21:14 · 11926 阅读 · 1 评论 -
C/C++ 用zlib解压gzip文件
见示例:其中调用inflate()后,zlib会保存解压进程,avail_in,next_in会更新,保存解压进程的断点。avail_out == 0说明这次输出内存用完,数据可能还没解压完,需要继续调用inflate(), 会从上次的位置继续解压。#include <stdio.h>/* For "exit". */#include <stdlib.h>/...原创 2020-02-26 11:26:31 · 10595 阅读 · 0 评论 -
makefile编译错误multiple definition of ***
makefie或者gcc编译的时候,如果出现multiple definition of *** 的错误,往往需要链接的源文件或者obj文件中有重名的函数(变量?),排除即可。如果是makefile,在同一个makefile中有多个target需要生成时,如:all: a ba: $(OBJS) gcc -o a $(OBJS)b: $(OBJS) gcc -o b $(OB...原创 2020-02-25 18:41:24 · 1766 阅读 · 0 评论 -
template模板函数一般要在头文件中定义
模板函数要在头文件中定义https://blog.csdn.net/tang05505622334/article/details/90478013转载 2020-02-25 18:32:25 · 696 阅读 · 0 评论 -
C++数字转字符串方法及性能
stringstreamstd::to_stringsprintfself definechrono原创 2020-01-09 21:19:47 · 791 阅读 · 1 评论 -
C++11新特性 std::enable_if的使用
std::enable_iftemplate原创 2020-01-09 19:48:22 · 1110 阅读 · 0 评论 -
Boost Multi-index Containers boost::multi_index_container
一、简介STL(standard template library)中的容器,如set, map,multimap, unordered_map等,可以存放key或key-value的数据, key是索引键,可以用来查找。 如为了记录员工信息:std::map<int, string> Employee;key是int型的表示员工号,value是string型的表示姓名。 但是有...原创 2019-12-13 20:53:59 · 375 阅读 · 0 评论 -
引用类型和类的引用类型成员变量
C++中,引用即别名,据说引用类型内部是指针实现的。 那么引用类型的变量占用内存的大小是不是和指针一样呢? 验证一下:std::cout << "size of pointer = " << sizeof(int*) << std::endl;std::cout << "size of int& = " << sizeof(i...原创 2019-11-30 16:11:42 · 778 阅读 · 1 评论