随笔分类 - c++随笔笔记
摘要:一、遍历函数 1.for_each遍历函数 #include<iostream> using namespace std; #include<algorithm> #include<vector> //for_each遍历函数 //普通函数 void pri(int val) { cout << v
阅读全文
摘要:1.map函数的概念与构造 #include<iostream> using namespace std; #include<map> void printmap(map<int, int>p) { for (map<int, int>::iterator it = p.begin(); it !=
阅读全文
摘要:#include<iostream> using namespace std; #include<string> //对组的创建,每一个对组中都有两个数据 //pair int main(void) { //第一种方式 pair<string, int>p("TOm", 5); cout << "第
阅读全文
摘要:#include<iostream> using namespace std; #include<algorithm> #include<vector> //二元谓词 class Mycmp { public: bool operator()(int val1, int val2) { return
阅读全文
摘要:#include<iostream> using namespace std; #include<vector> #include<algorithm> //一元谓词 //仿函数 返回值类型是bool数据类型,称为谓词 //一元谓词 class GreaterFive { public: bool
阅读全文
摘要:#include<iostream> using namespace std; //函数对象的基本使用 class MyAdd { public: MyAdd() { this->count = 0; } int operator()(int a, int b) { count++; return
阅读全文
摘要:#include<iostream> using namespace std; //运算符递增重载 class myint { friend ostream& operator<<(ostream& cout, myint a); public: myint() { m_a = 10; } //前置
阅读全文
摘要:#include<iostream> using namespace std; //c++重载左移运算符 class person { friend ostream& operator<<(ostream& cout, person& p); public: person(int a, int b)
阅读全文
摘要:#include<iostream> using namespace std; //普通函数和模板函数的区别: //1.普通函数调用可以发生类型转换 //2.函数模板 用自动类型推导 不可以发生隐式类型转换 //3.函数模板 用显示指定类型 可以发生隐式类型转换 int add01(int a, i
阅读全文
摘要:#include<iostream> using namespace std; //初识模板 //函数模板 template<typename T>//声明一个模板,告诉编译器后面代码中紧跟着的T不要报错,T是一个通用数据类型 void myswap(T *a, T *b) { T temp; te
阅读全文
摘要:#include<iostream> using namespace std; #include<fstream> int main(void) { //1.包含头文件 fstream //2.创建流对象 ofstream ofs; //3.指定打开文件 ofs.open("text.txt", i
阅读全文
摘要:#include<iostream> using namespace std; class Base { public: //纯虚函数 //类中只要有一个纯虚函数就叫做抽象类 //抽象类无法实例化对象 //子类必须重写父类中的纯虚函数,否则也属于抽象类 virtual void func() = 0
阅读全文
摘要:1.定义和初始化string对象 string s1 默认初始化,s1是一个空字符串 string s2(s1) s2是s1的副本 string s2 = s1 等价于s2(s1),s2是s1的副本 string s3("value") s3是字面值"value"的副本,除了字面值最后的那个空字符
阅读全文
摘要:#include<iostream> using namespace std; class Animal { public: //speak函数就是虚函数 //函数前面加上virtual关键字,变成虚函数,编译器在编译的时候就不能确定函数调用了 virtual void speak() { cout
阅读全文
摘要:#include<iostream> using namespace std; class person { public: person(int a, int b) { this->m_a = a; this->m_b = b; } //成员函数实现+号运算符重载 person operator+
阅读全文
摘要:#include<iostream> using namespace std; class Building; class goodgay { public: goodgay(); public: void visit(); void visit2(); private: Building* bui
阅读全文
摘要:#include<iostream> using namespace std; class building { //告诉编译器 goodgay全局变量 是buliding的好朋友,可以访问私有内容 friend void goodgay(building* B); public: building
阅读全文
摘要:#include<iostream> using namespace std; //静态成员函数的特点: //1.程序共享一个函数 //2.静态成员函数只能访问静态成员变量 class person { public: static void func() { b = 100; //c = 200;
阅读全文
摘要:#include<iostream> using namespace std; class base { public: int m_a; base() { m_a = 100; } void func() { cout << "base-调用" << endl; } void func(int a
阅读全文
摘要:#include<iostream> using namespace std; class base { public: base() { cout << "父类的构造函数" << endl; } ~base() { cout << "父类的析构函数" << endl; } }; class son
阅读全文

浙公网安备 33010602011771号