摘要:`gcc -print-prog-name=cc1` -v `gcc -print-prog-name=cc1plus` -v 或者: gcc -x c -v -E /dev/null gcc -x c++ -v -E /dev/null
阅读全文
摘要://BST.h #pragma once template <typename T> class BST; template <typename T> class BSTNode { public: friend class BST<T>; BSTNode() { lChild = rChild =
阅读全文
摘要:```cpp #ifndef SAFEQUEUE #define SAFEQUEUE #include <iostream> #include <queue> #include <thread> #include <mutex> #include <condition_variable> using
阅读全文
摘要:inline函数是C++引入的机制,目的是解决使用宏定义的一些缺点。 内联函数与宏定义区别 (1)内联函数在编译时展开,宏在预编译时展开; (2)内联函数直接嵌入到目标代码中,宏是简单的做文本替换; (3)内联函数有类型检测、语法判断等功能,宏没有; (4)inline函数是函数,宏不是; (5)宏
阅读全文
摘要:malloc/free和new/delete的区别 malloc/free是C/C标准库的函数;new/delete是C操作符。 malloc/free只是动态分配内存空间/释放空间;new/delete除了分配空间还会调用构造函数和析构函数进行初始化与清理资源。 malloc/free需要手动计算
阅读全文
摘要:比特(bit),即一个二进制位 ,例如100011就是6比特; 字节(byte),是计算机中数据类型最基本的单位,8bit组成1byte;1024byte组成1KB。 short(短整型),占2byte即16位,两个字节。 int(整型),占4byte即32位,一个int型数据的长度用4个字节来存储
阅读全文
摘要:#include<iostream> using namespace std; template <class T> void printArray(const T *array, int count) { for (int i=0; i< count; i++) { cout << array[i
阅读全文
摘要:#include <stdio.h> #include <stdarg.h> //void va_start(va_list arg_ptr, prev_param); //功能:以固定参数的地址为起点确定变参的内存起始地址,获取第一个参数的首地址. //va_list 类型的变量,va_list
阅读全文
摘要:#include <stdio.h> #include <string.h> //void* memchr(const void* str, int c, size_t n) //在参数 str 所指向的字符串的前 n 个字节中搜索第一次出现字符 c(一个无符号字符)的位置。 //返回一个指向匹配字
阅读全文
摘要:#include<stdio.h> #include<stdlib.h> #include<string.h> //void *malloc(size_t size) //分配所需的内存空间,并返回一个指向它的指针。若失败,则返回NULL //char* strcpy(char* dest, con
阅读全文
摘要:多个shared_ptr可以指向同一个对象,当对象不再使用时,shared_ptr被自动清理。 程序输出:
阅读全文
摘要:两种实现方式: 一种是自己写循环求和。 一种是使用numeric中的accumulate函数进行求和。 输出结果:
阅读全文
摘要:前言 C++ STL 提供了四种智能指针:auto_ptr、unique_ptr、shared_ptr 和 weak_ptr。其中auto_ptr 是 C++98 提供的解决方案,C+11 已将其摒弃,并提出了 unique_ptr 作为 auto_ptr 替代方案。虽然 auto_ptr 已被摒弃
阅读全文
摘要:```cpp#include#include using namespace std;templatestring ToString(T value){ stringstream strstream; strstream.str(""); strstream << value; return strstream.str();}int main(){ unsigned ...
阅读全文
摘要:概述 pair可以将两个数据组合成一种数据类型。 C++标准库中凡是必须返回两个值的函数都使用pair。 pair有两个成员变量,分别是first和second,由于使用的struct而不是class,因此可以直接访问pair的成员变量。 基本用法 pair的创建和初始化 声明: 初始化: 访问pa
阅读全文
摘要:Ctrl + M + O: 折叠所有方法 Ctrl + M + M: 折叠或者展开当前方法 Ctrl + M + L: 展开所有方法
阅读全文
摘要:输出结果: 列表初始化的顺序和类中成员变量声明的顺序一致。
阅读全文
摘要:```cpp #include #include using namespace std; int main() { const int arr_size = 5; int arr[arr_size] = {1,2,3,4,5}; // 第一种方式 vector vec(arr, arr+arr_size); // 从array数组向vector向量复制元素 for (int i=0; i vec
阅读全文
摘要:CentOS7安装高版本gcc 下载 从hust镜像站下载gcc源码包。 http://mirror.hust.edu.cn/gnu/gcc/ 我选择的是gcc 8.3.0.tar.gz。 下载依赖包: 配置 configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./conf
阅读全文