![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
c++学习过程知识分享与总结
DmrForever
这个作者很懒,什么都没留下…
展开
-
c++ double free错误解决
double free 问题原创 2022-09-06 17:05:08 · 1653 阅读 · 1 评论 -
c语言数组初始化的区别
字符数组的初始化原创 2022-08-25 20:58:51 · 468 阅读 · 0 评论 -
new 异常处理
c++中new bad_alloc异常处理原创 2022-08-19 17:14:09 · 599 阅读 · 0 评论 -
链表交错c++解法
链表原创 2022-07-27 00:10:28 · 142 阅读 · 0 评论 -
c++实现LRU算法
c++实现LRU算法#include <iostream>#include <list>#include <utility>#include <vector>#include <unordered_map>#include <memory>using namespace std;class LRUCache {public: unordered_map<int, list<pair<in原创 2022-05-22 21:50:14 · 542 阅读 · 0 评论 -
c++前缀树实现
c++前缀树实现#include <iostream>#include <vector>#include <unordered_map>#include <memory>template<typename V>class TrieMap {public: class Option { public: V val{}; bool isNone = true; };priv原创 2022-05-22 21:49:16 · 300 阅读 · 0 评论 -
单调队列c++解决滑动窗口最大值问题
单调队列c++解决滑动窗口最大值问题单调队列中的元素以单调递增或递减方式排列,可以解决leetcode239. 滑动窗口最大值。这里单调队列使用了std::list即双端链表实现,队列中元素单调递减排列。class MonotonicQueue{ public: void push(int n){ // 将队列中小于n的元素全部删除 while(!mQueue.empty() && mQueue.back() &l原创 2022-05-22 21:48:12 · 248 阅读 · 0 评论 -
rapidjson序列化Map
序列化Map, 与nlohmann json输出相同#include <map>#include "rapidjson/document.h"#include "rapidjson/writer.h"#include "rapidjson/stringbuffer.h"using namespace rapidjson;using rapidjson::StringBuffer;using rapidjson::Writer;using namespace rapidjson;原创 2022-05-22 21:46:17 · 525 阅读 · 0 评论 -
c++ vector size()遍历错误记录
在一次编程中,通过for循环递减遍历vector,忽略了vector.size()函数的返回值类型,导致了如下的越界错误。std::vector<int> mi{1,2,2};auto s = mi.size();// vector 的size()函数返回的是unsigne Long型for(auto i = s -1; i >= 0;i--){ std::cout << i << std::endl;}21018446744073709原创 2022-05-22 21:45:04 · 521 阅读 · 0 评论 -
c++模板元编程学习记录
现代模板元编程 - 第一部分 - Cppcon 2014 - Walter E. Brown#include<stdio.h>// example 1template<unsigned M, unsigned N>struct gcd{ static int const value = gcd<N, M % N>::value;};template<unsigned M>struct gcd<M, 0> {原创 2022-05-22 21:31:33 · 118 阅读 · 0 评论 -
c语言unsigned int和int
```c#include<stdio.h>#include<stdlib.h>#include<string.h>voidmain(){inta=-1;unsignedintb=-1;printf("%d\n",a);printf("%u\n",b);//<...原创 2020-04-15 20:35:01 · 1257 阅读 · 0 评论 -
一个数组实现双堆桟--C语言
用一个数组实现双堆桟,最大的利用数组空间,使只要数组有空间就能入栈成功。1、定义一个双堆桟#define MaxSizestruct DStack{ ElementType Data[Maxsize]; int Top1; int Top2;}S;S.Top1=-1;S.Top2=MaxSize;2、实现双堆桟的入栈void Push(struc...原创 2018-10-01 19:31:59 · 306 阅读 · 0 评论 -
c语言实现链表
c语言的动态内存管理函数实现动态内存管理;1、malloc() 函数void *malloc(unsigned int size);分配一块长度为size字节的连续空间,并将该空间的首地址作为函数的返回值。2、calloc()函数void *calloc(unsigned int n, unsigned int size);分配一块长度为n*size字节的连续空间,并将该...原创 2018-09-19 19:48:55 · 223 阅读 · 0 评论 -
C++读取文件
C++读文件#include <iostream>#include <fstream>int main() { std::ifstream inputFile("test.json"); if (!inputFile.is_open()) perror("open file false"); std::string str((std::istreambuf_iterator<char>(inputFile)), std::istreambu原创 2021-07-06 11:16:20 · 297 阅读 · 0 评论 -
c++11中的std::initialzer_list
c++11中的stl容器拥有和未显示指定长度的数组一样的初始化能力。其初始化列表长度可以是任意的。std::initialzer_list这一轻量级类模版提供了上述功能的支持。例如可以使用std::initialzer_list定义自己的容器:class MyVector{ std::vector<int> content_;public: MyVector(std::initializer_list<int> list){ for(a原创 2020-06-25 19:33:31 · 867 阅读 · 0 评论 -
C++实现LRU算法
利用双向链表和哈希表实现LRU算法双向链表使用双向链表可以快速删除和添加元素,来移动最近使用的节点,将最近使用的节点保存到双向链表的尾端。快速的put值和value。哈希表使用哈希表可以快速的查找节点。快速get关键值为key的value。LRU算法实现 LRUCache 类:LRUCache(int capacity) 以正整数作为容量 capacity 初始化 LRU 缓存int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1 。void原创 2021-11-14 20:50:53 · 1612 阅读 · 0 评论 -
c++通过宏控制Log日志的显示与否
c++通过宏控制Log日志的显示与否当使用log打印日志消息时,有的日志不想输出,所以希望通过参数动态配置显示与否。采用宏定义和static变量的方式控制日志的显示与否。代码LogController.h#include <logger.h>namespace cs { namespace logger { class LogController { private: static bool isShowLog;原创 2021-06-24 21:22:30 · 605 阅读 · 2 评论 -
c++从txt文件读取一个矩阵数据
#include <iostream>#include <vector>#include <fstream>#include <zconf.h>#include <string>#include <sstream>std::vector<std::vector<double >> readMatrixFile(const char *fileName) { // get current .原创 2020-09-26 11:42:23 · 7457 阅读 · 1 评论 -
C++字节对齐及sizeof struct
C++字节对齐及sizeof struct参考sizeof的结果怎么来的,请牢记以下3条原则:(在没有#pragma pack宏的情况下)1:数据成员对齐规则:结构(struct)(或联合(union))的数据成员,第一个数据成员放在offset为0的地方,以后每个数据成员存储的起始位置要从该成员大小的整数倍开始(比如int在32位机为4字节,则要从4的整数倍地址开始存储。2:结构体作为成员:如果一个结构里有某些结构体成员,则结构体成员要从其内部最大元素大小的整数倍地址开始存储.(struc原创 2020-10-26 19:36:57 · 197 阅读 · 0 评论 -
C++使用Hadoop
安装Hadoop这里推荐一篇文章,我感觉写得很详细,跟着流程安装起来很容易。install-hadoop-on-ubuntu-20-04使用Hadoop注意事项hadoop有用户组,有用户权限区分,其他linux用户使用需要加入权限。hadoop安装好以后,如果不能正常使用,查看环境变量CLASSPATH和USER。在终端可以成功运行,但是在Clion编辑器里面也需要考虑环境变量。三种C++调用Hadoop API的方式使用libhdfs,一个c语言调用java JNI的库。例如:原创 2021-11-14 22:58:15 · 2493 阅读 · 0 评论 -
c语言bitField
#include <cstdio>void printf_bin2(void *dataPtr, int sizeOfData) { int i, j; unsigned char *p = (unsigned char *) dataPtr + (sizeOfData - 1);//p先指向num后面第3个字节的地址,即num的最高位字节地址 for (i = 0; i < sizeOfData; i++) //依次处理4个字节(32位) {原创 2022-04-12 10:10:08 · 812 阅读 · 0 评论