![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
Noch
这个作者很懒,什么都没留下…
展开
-
本地套接字
服务端#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/socket.h>#include <sys/types.h>#include <sys/un.h>//抽象路径名#define file_path "nochs"int main(int argc, char *argv[]){ int listen_fd;原创 2022-03-14 14:10:32 · 125 阅读 · 0 评论 -
Linux平台基于消息队列的C++简易封装
#pragma once#include <cstdio>#include <cstdlib>#include <sys/msg.h>#include <cstring>#include <atomic>typedef void (*mq_recv_call_handler)(int recv_len,char *recv_buf);struct msg_st{ long int msg_type;//作为一个标志,非原创 2022-03-11 10:18:25 · 1484 阅读 · 0 评论 -
c/c++调用Lua,接口简单封装
封装源码extern "C"{#include "src/lua/include/lua.h"#include "src/lua/include/lauxlib.h"#include "src/lua/include/lualib.h"}#include <iostream>#include <cstring>#include <string>#include <stdarg.h>#include <unordered_map&g原创 2022-03-11 09:49:34 · 487 阅读 · 0 评论 -
基于select的IO多路复用样例
NTcp.h文件#ifndef NTcp_H#define NTcp_H#include <iostream>#include <functional>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <cstring>#include <thread>#include <string>#原创 2022-03-11 09:05:56 · 211 阅读 · 0 评论 -
示例`CMakeLists.txt`
示例CMakeLists.txt。#1 设置cmake版本cmake_minimum_required( VERSION 3.9 )#2 设置项目名称project( cli_modbus )#3 设置编译器版本set( CMAKE_CXX_STANDARD 11 )set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")# #打印JYSP_HOME环境变量# message(STATUS "JYSP_HOME:$ENV{JYSP_原创 2022-01-17 10:59:17 · 582 阅读 · 0 评论 -
split
/*buf:待分割字符串delim:分隔符*/std::vector<std::string> split(const std::string &buf, const std::string &delim){ std::vector<std::string> elems; size_t pos = 0; size_t len = buf.length(); size_t delim_len = delim.length();原创 2021-12-27 14:19:38 · 228 阅读 · 0 评论 -
比较:strcmp(),strncmp(),strcasecmp(),strncasecmp()
一、strcmp vs strncmp1、strcmp头文件:#include <string.h>函数原型: int strcmp(const char *str1, const char *str2)描述: 比较str1和str2的大小参数:str1 —— 待比较的第一个字符串str2 —— 待比较的第二个字符串返回值:str1 > str2 返回值 > 0str1 = str2 返回值 = 0str1 < str2 返回值 < 02、s原创 2020-12-31 09:43:41 · 1899 阅读 · 0 评论 -
获取线程ID的方法
#获取线程ID的方法获取线程ID的方法Linuxphread_createpthread_selfsyscallWindows_beginthreadexGetCurrentThreadIDC++11std::this_thread::get_id和std::thread::get_idLinuxphread_create调用pthread_create函数时,第一个参数在函数调用成功后可以得到线程ID:#include <pthread.h>// 线程IDpthread_t i原创 2020-11-27 10:49:47 · 7460 阅读 · 1 评论 -
Qt添加自动化备注
文件注释/*******************************************************************************@作者: XXX*@添加时间:%{CurrentDate:ISO} %{CurrentTime:ISO}*@所属项目:%{CurrentProject:Name}*@当前文件:%{CurrentDocument:FilePath}*@文件描述:*@三十功名尘与土,八千里路云和月*********************.原创 2020-09-29 13:44:17 · 523 阅读 · 0 评论 -
基础算法的基础实现
冒泡平均时间复杂度 :O(n²) 最好情况 :O(n)最坏情况 :O(n²) 空间复杂度 : O(1)稳定性:稳定代码实现:void BubbleSort(int *num,int size){ while (true) { for (int i = 0; i < size -1; ++i) { if (num[i] > num[i+1]) {...原创 2020-04-24 14:30:50 · 148 阅读 · 0 评论 -
关于c/c++标准库的记录
printf家族1、printf, fprintf, sprintf, snprintf, printf_s, fprintf_s, sprintf_s, snprintf_s定义于头文件 <stdio.h>(1) int printf( const char *format, … );(C99 前)int printf( const char *restrict f...原创 2020-04-21 10:35:43 · 324 阅读 · 0 评论 -
记录大小端说明
大小端说明内容取自《深入理解计算机系统》(第三版)某些机器选择在内存中按照从最低有效字节到最高有效字节的顺序存储对象,而另一些机器则按照从最高有效字节到最低有效字节的顺序存储。前一种规则——最低有效字节在最前面的方式,称为***小端法***。后一种规则——最高有效字节在最前面的方式,成为***大端法***。大多数Intel兼容机只用小段模式。如:Windows...原创 2020-04-20 09:44:16 · 128 阅读 · 0 评论 -
懒汉模式的常规使用
设计模式之单例模式@TOCSingleton Pattern这里不做模式的分析讨论,仅针对使用过的用法进行演示。最早使用的方法:.h#include <mutex>class A {public: explicit A(); ~A(); static A *Instance() { //检测实例是否存在 if (!self) { std::...原创 2020-04-13 10:13:20 · 302 阅读 · 0 评论