![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
C/C++
C/C++编程语言学习
酸菜。
爱生活,爱TXJ。
展开
-
提取文件路径和文件名称,文件大小
获取文件路径,名称,大小原创 2022-12-09 11:46:56 · 928 阅读 · 3 评论 -
c语言进度条显示备忘
进度条显示原创 2022-11-25 11:19:08 · 338 阅读 · 0 评论 -
inet_pton和inet_ntop使用总结
inet_ntop和inet_pton原创 2022-11-08 13:41:11 · 812 阅读 · 0 评论 -
realloc函数使用小结
c api函数使用小结原创 2022-10-08 11:07:31 · 108 阅读 · 0 评论 -
STL list总结
STL list概念list是一种序列式容器。list类似于双向循环链表,所以,list的插入和删除都是较快的,但是它的内存空间是不连续的,要通过指针来进行数据的访问,这个特点使得它的随即存取变的非常没有效率。使用时包含list头文件。初始化插入元素insertinsert(it position,const value& i)insert(it position, size_t n ,const value& i)insert(it position, input fi原创 2021-05-24 15:13:42 · 206 阅读 · 1 评论 -
STL总述,发展史,组成。
一:总述(1)c++标准库: c++ standard Library。只要你装了c++编译器,那么这个c++标准库自动就被安装进来了;vector,可复用;用好标准库,是一个合格的c++程序员的追求之一。(2)标准模板库:Standard Template Library(STL),包含在c++标准库之中,作为c++标准库中的一个重要组成部分或者说是c++标准库的核心,深刻的影响着标准库;(3)泛型编程:Generic Programming。使用模板template为主要的编程手段来编写代码。原创 2021-02-06 16:15:56 · 284 阅读 · 4 评论 -
c++代理模式
一:常见的代理模式远程代理(Remote Proxy)虚拟代理(Virtual Proxy)保护代理(Protect Proxy)缓存/缓冲代理(Cache Proxy)智能引用代理(Smart Reference Proxy)shared_ptr写时复制(copy-on-write)优化代理:string防火墙代理、同步代理,复杂隐藏代理等。二:范例学习购物网站代理:#include <iostream>#include <vector>#include &原创 2022-03-04 15:51:04 · 845 阅读 · 0 评论 -
c++单件模式
单件模式也称为单例模式或者单态模式,这是一种创建型模式,创建只能产生一个对象实例的类。只能创建一个属于该类对象的类就称为单件类。也许有人好奇,只能创建一个对象的类,那么我在程序当中只创建一个该对象不就行了吗?这个类还需要设计吗?是的,但是著名c++界的Scott Meyers说过"要使接口或者类型易于正确使用,难以错误使用",,也就是说只能创建一个属于该类对象的类的工作应该要交给类的设计者去实现这个事情,而不是把这个工作交给类的使用者去考虑这个事情。单例模式的样式有很多,本篇博文就这些范例来个总结吧。原创 2021-09-13 18:58:42 · 694 阅读 · 0 评论 -
c++ 命令模式
范例一:#include <iostream>using namespace std;class cook{public: void fish() { std::cout << "doing fish" << std::endl; } void meat() { std::cout << "doing meat" << std::endl; }};cla原创 2022-03-13 18:21:40 · 1007 阅读 · 0 评论 -
c++设计模式概览
原创 2021-04-19 22:03:12 · 107 阅读 · 0 评论 -
c++桥接模式
范例一:#include <iostream>#include <thread>#ifdef _DEBUG //只在Debug(调试)模式下#ifndef DEBUG_NEW#define DEBUG_NEW new(_NORMAL_BLOCK,__FILE__,__LINE__) //重新定义new运算符#define new DEBUG_NEW#endif#endifusing namespace std;//#pragma warning(disab原创 2021-10-03 10:53:54 · 415 阅读 · 0 评论 -
c++观察者模式
范例一:#include <iostream>#include <vector>using namespace std;#pragma warning(disable : 4996) class Fighter;vector<Fighter*> obj;class Fighter{private: string m_name; int m_id; int m_fimalyid;public: Fighter(string name, int原创 2021-08-29 15:09:41 · 119 阅读 · 0 评论 -
c++访问者模式
#include <iostream>#include <list>#include <string>using namespace std;class parkBase;class visitor {public: virtual void visitApark(parkBase* park) = 0; virtual void visitBpark(parkBase* park) = 0; virtual ~visitor() {}原创 2022-01-21 17:55:38 · 522 阅读 · 0 评论 -
c++职责链模式
#include <iostream>using namespace std;#pragma warning(disable : 4996) /*定义一个加薪请求类*/class RaiseRequest{public: string m_name; /*加薪请求者姓名*/ int m_salary;/*加薪请求数量*/public: /*构造函数*/ RaiseRequest(string name, int salary) :m_name(name), m_salar原创 2021-08-28 16:26:24 · 278 阅读 · 0 评论 -
c++ 门面模式/外观模式
#include <iostream>#include <type_traits>using namespace std;class MakeCar {public: void makefun() { makecarhead(); makecarbody(); makecartail(); } virtual void makecarhead() = 0; virtual void makecar原创 2022-03-08 21:21:34 · 248 阅读 · 0 评论 -
c++享元模式
#include <iostream>#include <list>#include <map>using namespace std;enum class EnumColor //棋子类型{ Black, //黑 White //白};struct Position //棋子位置{ int m_x; int m_y; Position(int tmpx, int tmpy) :m_x(tmpx), m_y(tmpy) {} //构造函原创 2021-09-12 22:52:24 · 178 阅读 · 0 评论 -
函数模板可变参
英文:Variadic Templates ,C++11一:函数模板可变参1.1:基本范例template <typename ...T>//T是一包类型,...是固定语法void fun(T ...args)//args是一包参数,注意...的位置{ cout << sizeof...(args) << endl; //输出参数的个数 cout << sizeof...(T) << endl;//输出参数的个数}允原创 2021-11-10 17:07:38 · 821 阅读 · 0 评论 -
成员函数模板,显示实例化与声明
一:普通类的成员函数模板#include "pch.h"#include <iostream>using namespace std;class B{public: int a;public: template<typename U> void fun(U obj) { cout<<"void fun(U obj)"<<endl; cout << obj << endl; } template<原创 2021-04-17 22:30:37 · 712 阅读 · 0 评论 -
萃取(trait)技术与策略(policy)技术当中的值萃取(value traits)
一:值萃取(value traits)演示在这里插入代码片二:常规例程演示在这里插入代码片三:判断是否为void类型范例演示在这里插入代码片四:判断两个类型是否相同在这里插入代码片原创 2022-03-26 11:58:50 · 428 阅读 · 0 评论 -
可变参模板之折叠表达式
一概述:折叠表达式,Fold Expressions,C++17目的:计算某个值(表达式的结果当然是一个值)该值得特殊性在于:它与所有可变参有关,而不是与单独某个可变参有关。需要所有可变参都参与计算,才能求出该值。分类:折叠表达式有四种格式:一元左折、一元右折,二元左折、二元右折。注意,每种格式的折叠表达式都需要用圆括号括住。左折:就是参数从左侧开始计算右折:参数从右侧开始计算二:范例2.1:一元右折2.2:一元左折2.3:二元右折2.4:二元左折...原创 2021-11-12 17:19:09 · 1303 阅读 · 0 评论 -
类模板的隐式推断指南c++17
#include <iostream>#include <string>using namespace std;template <typename T>class A{public: A(T tmpt) { }};int main(){ //c++17开始可以这样写了(依赖推断指南),不用写成以下形式了 A<int> a(1); A a(1); return 0;}#include &l原创 2022-02-12 21:29:56 · 572 阅读 · 0 评论 -
c++ SFINAE特性
/* 替换失败并不是一个错误(SFINAE),SFINAE:Substitution Failure Is Not An Error 理解:编译器内部遵循的原则,c++语言的一个特性。 SFINAE特性是针对“函数模板重载”而言。 针对于函数模板而言,当用一个具体类型替换函数模板的参数时,可能会产生意想不到的问题 : 比如产生一些毫无意义甚至是看起来语法上有错误的代码,对于这些代码,编译器并不一定报错, 有可能是忽略——编译器认为这个函数模板不匹配针对本次的函数调用,就当这个函数模板原创 2022-02-26 14:20:07 · 507 阅读 · 0 评论 -
模板代码结构书写浅谈
当前项目目录:A.h#ifndef A_H#define A_H#include "iostream"template<typename T>class A {public: void fun();};#endifA.cpp#include "A.h"template <typename T>void A<T>::fun(){}main.cpp#include<iostream>#include "A.h原创 2021-11-19 13:20:49 · 389 阅读 · 0 评论 -
可变参类模板的特化(偏特化和全特化)
#include<iostream>using namespace std;/*泛化版本*/template<typename ...args>class A {public: A() { printf("泛化版本%p\n", this); }};/*偏特化版本,拆开成一个和一包*/template <typename first, typename... args>class A<first,args.原创 2021-11-20 21:01:58 · 711 阅读 · 0 评论 -
成员函数的全特化
成员函数的全特化(不是类模板全特化和函数模板全特化)#include "pch.h"#include "test.h"#include <iostream>#include <map>using namespace std;//泛化版本template<typename T,typename U>struct A{ A() { cout << "泛化A()" << endl; } void func() { c原创 2021-04-21 15:21:52 · 503 阅读 · 0 评论 -
可变参表达式
#include<iostream>using namespace std;template <typename... T>auto print(T const&... args){ //2,8,14,4,每个参数扩大两倍的结果 (cout << ... << args) << " 结束" << endl; return (... + args); //计算一下参数和值}template &l原创 2021-11-13 14:46:15 · 529 阅读 · 0 评论 -
非类型的类模板参数
//main.cpp#include "pch.h"#include <iostream>#include "stack1.h"#include<string>using namespace std;int main(){ //类的非类型模板参数 _space3::stack<int, 10> sint10; for (int i = 0; i < 10; i++) { sint10.push(i); } cout <<原创 2021-02-28 13:25:18 · 155 阅读 · 0 评论 -
类模板的特化与局部特化
//main.c#include "pch.h"#include <iostream>#include "stack1.h"#include<string>using namespace std;int main(){ // int i = 0, ret = 0; _space1::stack<int> s;//实例化 for (i = 0; i < 10; i++) { s.push(i); } ret = s.top(); c原创 2021-02-27 17:58:15 · 173 阅读 · 0 评论 -
std::is_union,std::is_class,std::integral_constant
#include <iostream>#include <string>using namespace std;struct A { int num; char type;};union B { int num; char type;};int main(){ /*std::is_union是类模板。用于判断某个类型是否是一个联合类型 如果是联合,value就为true(1),否则为false(0),判断原理与编译器原创 2022-02-13 19:09:54 · 626 阅读 · 0 评论 -
c++ std::void_t使用小结
一:std::void_t源码// ALIAS TEMPLATE void_ttemplate <class... _Types>using void_t = void;二:特性(功能)能够检测到应用SFINAE(替换失败并不是一个错误)特性时出现的非法类型。换句话说,给进来的类型 _Types 必须是一个有效的类型,不能是一个非法类型三:使用场景,配合std::false_type 与std::true_type判断一个类当中是否存在一个类型别名,成员变量,函数等。#inc原创 2022-03-06 19:58:08 · 1835 阅读 · 0 评论 -
函数模板总结
函数模板基本范例认识函数模板(1)背景:就以两个数相加来说,如果两个数是整型,那么我们可能要写一个函数像下面这样, int add(int i,int j) { return i+j; } 而如果两个数是浮点类型,那么函数可能要这样写,float add(float i,float j){ return i+j;}(2)解决办法:那么有没有什么办法可以优化一下,有,为了减少代码的冗余性,于是函数模板就出现了。(3)关于函数模板的理解:3.1可以理解为原创 2021-02-21 12:39:24 · 286 阅读 · 1 评论 -
c++ 萃取容器里元素里的类型以及元素个数。
#include <iostream>#include <list>#include <vector>#include <map>#include <deque>#include <type_traits>using namespace std;/*泛化版本*/template<typename T>class GetContainerType;/*特化版本*/template<typenam原创 2022-03-16 13:55:47 · 1536 阅读 · 0 评论 -
std::true_type和std::false_type详解
std::true_type和std::false_type认识我们先通过一个例程来认识下它吧。#include <iostream>using namespace std;int main(){ std::true_type a; std::false_type b; std::cout << a << std::endl; std::cout << b << std::endl; return 0;原创 2022-01-06 00:25:36 · 6453 阅读 · 1 评论 -
using指定模板类型,以及显示指定模板参数
一:using指定模板类型/* note:看到以下两个类型当中,map(key类型相同)仅仅是因为value的类型不同而已,一个是string,一个是int,那么有没有办法可以为这个这么长的类型定义一个别名呢?当然,typedef std::map<std::string, std::string> map_s_s 可以,但是,如果value的类型是不确定的,那么用typedef显然是不行的。 解决方案有两种:*/ std::map<std::string, std::strin原创 2021-04-19 21:38:48 · 474 阅读 · 0 评论 -
类模板缺省模板实参
可以为类模板的形参指定缺省实参。//main.cpp#include "pch.h"#include <iostream>#include "stack1.h"#include<string>using namespace std;int main(){ // _space2::stack<int> elem1; for (i = 10; i < 20; i++) { elem1.push(i); } if (!elem1.empt原创 2021-02-27 21:14:52 · 495 阅读 · 0 评论 -
c++ Templates技巧性基础知识
技巧性基础知识关键字typename#include "pch.h"#include <iostream>#include<string>using namespace std;class U{public: U():i(100) { cout << "U()" << endl; }public: /*在类U里声明一个静态int类型变量*/ static int sub; /*无符号整型重定义*/ typedef unsi原创 2021-03-06 17:12:56 · 154 阅读 · 1 评论 -
联合体模板
#include <iostream>#include <vector>#include <list>#include <boost/type_index.hpp>using namespace std;#pragma warning(disable : 4996) //联合也支持模板化。template<typename T, typename U>union myuni{ T carnum; //轿车编号,4个字节。原创 2021-11-06 12:22:11 · 131 阅读 · 0 评论 -
类模板中的友元,友元类
一:让类模板的某个实例成为友元。#include <iostream>#include <vector>#include <list>using namespace std;#pragma warning(disable : 4996) template <typename T> class B; //声明template <typename T>class A{ friend class B<int>; //针原创 2021-11-06 14:45:30 · 606 阅读 · 0 评论 -
固定萃取,除去引用类型和增加引用类型
一:范例一#include <iostream>#include <type_traits>using namespace std;template<typename T, typename U>void print_is_sametype(){ std::cout << typeid(T).name() << std::endl; std::cout << typeid(U).name() <<原创 2022-03-18 18:33:37 · 462 阅读 · 0 评论 -
实现std::decay类模板的类似功能(退化)
#include <iostream>#include <type_traits>#include <boost/type_index.hpp>using namespace std;/*去除const属性,泛化版本*/template<typename T>struct removeconst{ using type = T;};/*去除const属性,特化版本*/template<typename T>struct原创 2022-03-20 18:33:31 · 269 阅读 · 0 评论