- 博客(21)
- 收藏
- 关注
原创 模板全特化和偏特化用法
#include <iostream>template <typename T, typename U>class TC{public: TC() { std::cout << "泛化版本构造函数" << std::endl; } void funtest() { std::cout << "泛化版本成员函数" << std::endl; }...
2021-03-31 15:48:16 82
原创 随机生成指定位数字符串
#include<string>#include<mutex>std::string gen_random_string(int length){ static const char char_space[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; static std::once_flag once; static const size_t...
2021-03-30 14:21:40 226
原创 网络地址 子网掩码 广播地址计算
已知一个ip地址是192.168.1.1,子网掩码是255.255.255.0,那么它的网络地址是多少?192.168.1.0已知某主机的ip地址是192.168.100.200,子网掩码为255.255.255.192,其网络内可用的ip地址个数为多少621111 1111 1111 1111 1111 1111 1100 0000某公司申请到一个C 类IP 地址,只连接6 个子公司,最大的一个子公司有26 台计算机,每个子公司都分配在同一个网段,则子网掩码应设为多少合适?C类地址,网络
2021-03-30 09:55:17 1630
原创 string实现
class String{public: String() { ptr_ = new char[1]; *ptr_ = 0; } explicit String(const char* str) { int data_size = strlen(str); if (data_size == 1) { ptr_ = new char[1]; *ptr_ ...
2021-03-29 17:07:16 51
原创 实时监控文件操作
#include <iostream>#include <windows.h>#include <thread>#include <vector>#define BUFFER_SIZE 2048std::vector<char>g_buffers;// 监控函数BOOL MonitorFile(std::wstring&path) { PTCHAR pszDirectory =(PTCHAR)(path.c_...
2021-03-23 18:46:37 303
原创 emplace_back和push_back区别
#include <vector>#include <iostream>using namespace std;class testDemo{public: testDemo(int num) :num(num) { std::cout << "调用构造函数" << endl; } testDemo(const testDemo& other) :num(other.num) { s...
2021-03-23 18:45:53 133
原创 细分shared_ptr智能指针在各个版本的使用情况
#include <memory>#include <iostream>class A{public: A(int value) :value_(value) { }private: int value_;};int main(){ //c++17之前语法 std::shared_ptr<int> shared_good(new int[10],std::default_delete<int[]&g...
2021-03-23 14:56:23 92
原创 lambda配合enable_shared_from_this使用造成内存泄漏问题
#include <iostream>#include <memory>#include <iostream>#include <string>#include <functional>class client:public std::enable_shared_from_this<client>{ using CallBack =std::function<void(std::string&&a...
2021-03-18 11:00:50 485
原创 c++ for each 遍历tuple
#include <iostream>#include <tuple>namespace detail{ template<int... Is> struct seq { }; template<int N, int... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> { }; template<int... Is> stru...
2021-03-17 11:29:13 883
原创 asio编写串口通信
#include <iostream>#include<boost/asio.hpp>#include <string>int main(){ boost::asio::io_context ios; std::string buffer; buffer.resize(1024); boost::asio::serial_port ser_port(ios); ser_port.open("COM1"); ser...
2021-03-16 11:15:07 730
原创 asio socket nonblocking模式
//// third_party_lib.cpp// ~~~~~~~~~~~~~~~~~~~//// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)//// Distributed under the Boost Software License, Version 1.0. (See accompanying// file LICENSE_1_0.txt or copy at http:/.
2021-03-15 10:34:51 450
原创 浅谈asio中async_accept函数占用内存高的写法
相比大家都使用过asio 中的async_accpect如果使用的好,内存会占用的小,下面来看一端实列:
2021-03-15 10:13:54 1463
原创 关于asio下的async_accept的节省内存空间的写法
#include <iostream>#include <boost/asio.hpp>boost::asio::io_context ios;int main(){ auto work = boost::asio::make_work_guard(ios); boost::asio::ip::tcp::endpoint ept(boost::asio::ip::tcp::v4(), 9090); boost::asio::ip::tcp::a...
2021-03-13 09:47:01 961
原创 字符串转数字
支持负的字符串转换int str_to_num(const std::string& str){ bool falg = false; size_t pos = str.find("-"); size_t index = 0; if (pos != std::string::npos){ ++index; falg = true; } int value = 0; size_t data_size = s...
2021-03-11 11:18:54 71
原创 整数转字符串
//支持负数转字符串std::string num_to_str(const int value){ std::string str; std::string falg; int temp_value = 0; if (value < 0) { falg += "-"; temp_value -= value; }else { temp_value = value; } while...
2021-03-11 11:01:40 66
原创 字符串逆序
void str_reverse(char* str){ size_t right_index = strlen(str)-1; size_t left_index = 0; while (left_index < right_index){ char temp = str[left_index]; str[left_index++] = str[right_index]; str[right_index--] = temp;...
2021-03-11 10:31:20 64
原创 关于asio::io_context没有事件保证不退出
#include <iostream>#include <thread>#include <boost/asio.hpp>#include <chrono>std::string raw_ip_addr = "127.0.0.1";unsigned short port_num = 6768;int main() { boost::asio::io_context ioc; boost::asio::ip::tcp::endpo...
2021-03-10 10:51:29 539
原创 git仓库迁移
git push --mirror 目标仓库地址(ssh 地址)此命令属于完美迁移,会把当前项目下的所有分支和log全部迁移到目标地址上。
2021-03-09 15:44:15 156
原创 用string类中的find函数实现split
#include<string>#include<vector>void split(std::vector<std::string>& result, const std::string& str, std::string demli){ size_t pos = 0; size_t start = 0; size_t data_size = str.size(); while (pos<data_size...
2021-03-09 11:06:04 190
原创 用vs编译openssl静态库
Perl Configure VC-WIN64A no-asm --openssldir="D:\openssl_lib"perl Configure VC-WIN32 no-asm --openssldir="D:\openssl_lib"
2021-03-05 15:17:53 205
原创 c++跨平台写法
#if __cplusplus >= 201703L || (defined _MSC_VER && _MSC_VER > 1900)#include <string_view>#else#include <boost/utility/string_view.hpp>#include <boost/functional/hash.hpp>#endif
2021-03-05 10:07:19 278 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人