
C++
国安永远争第一
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
g++ 安装教程
参考博客1:有调试实例 https://jingyan.baidu.com/article/acf728fd7a6db0f8e410a345.html参考博客2:安装教程https://blog.youkuaiyun.com/IUNIQUE/article/details/84257298?depth_1-utm_source=distribute.pc_relevant.none-task&am...原创 2020-04-01 08:56:58 · 733 阅读 · 0 评论 -
C++课堂笔记整理(STL) set 3
#include <iostream>#include <functional>using namespace std;#include "set"class Student{public: Student(char *name, int age) { strcpy_s(this->name, name); this->age = a...原创 2019-02-13 09:44:02 · 151 阅读 · 0 评论 -
08 一元函数对象和一元谓词
#include <iostream>using namespace std;#include "string"#include <vector>#include <list>#include "set"#include <algorithm>#include "functional"//函数对象 类重载了函数调用原创 2019-02-13 21:51:15 · 182 阅读 · 0 评论 -
大学生C++教程第九版 习题(10.10)
//RationalNumber.h#ifndef RATIONALNUMBER#define RATIONALNUMBER#include <iostream>#include <string>#include <cmath>#include <stdexcept>using namespace std;class Ration...原创 2019-02-28 20:47:24 · 1182 阅读 · 1 评论 -
笔记整理:二元函数对象和二元谓词
#include <iostream>using namespace std;#include "string"#include <vector>#include <list>#include "set"#include <algorithm>#include "functional"void FuncShowEle原创 2019-02-14 11:11:30 · 304 阅读 · 0 评论 -
二元谓词在set集合中的应用01
#include <iostream>using namespace std;#include "set"#include <string>#include <algorithm>#include <functional>struct CompareNoCase{ bool operator()(const string &am...原创 2019-02-14 12:59:43 · 238 阅读 · 1 评论 -
预定义对象和函数适配器1
#include <iostream>using namespace std;#include "set"#include <string>#include <vector>#include <algorithm>#include <functional>//plus<int> 预定义好的函数对象 能实原创 2019-02-14 14:35:24 · 114 阅读 · 0 评论 -
运算符重载笔记
1 复习函数重载 C++允许多个具有想通过名字的函数,只要这些函数具有不同的函数签名。这些特性被称为函数重载。当调用一个重载函数时,C++编译器通过检查函数调用中的实参数目、类型和顺序来选择适当的函数。函数重载通常作用于创建执行相似任务、但是作用于不同数据类型的具有相同名字的多个函数。//实例一 计算圆和圆柱的面积 #include <iostream&...原创 2019-02-20 08:35:46 · 236 阅读 · 0 评论 -
P207_运算符重载入门基础推演
#include <iostream>using namespace std;class Complex{public: int a; int b;public: Complex(int a = 0, int b = 0) { this->a = a; this->b = b; } void printCom() { cout &l...原创 2019-02-20 11:18:53 · 179 阅读 · 0 评论 -
P210_成员函数和友元函数完成二元运算符的两种方法
#include <iostream>using namespace std;class Complex{ friend Complex operator+(Complex &c1, Complex &c2);private: int a; int b;public: Complex(int a = 0, int b = 0) { this-...原创 2019-02-20 15:19:10 · 239 阅读 · 0 评论 -
大学生C++教程第九版 习题(7.21)
#ifndef PROGRAM_H#define PROGRAM_H#include <iostream>#include <iomanip>using namespace std;#include <array>#include <string>class Program{public: static const size_t...原创 2019-03-05 11:14:33 · 664 阅读 · 0 评论 -
函数对象和函数对象当返回值和参数
#include <iostream>using namespace std;#include "string"#include <vector>#include <list>#include "set"#include <algorithm>#include "functional"//函数对象 类重载了函数调用原创 2019-02-13 21:27:17 · 155 阅读 · 0 评论 -
使用指针时常犯的编程错误
1、内存泄漏如果使用new动态分配的内存不再需要后,程序员没有使用配套的delete释放,通常就会出现这种情况。参考博客:https://blog.youkuaiyun.com/Clever_Pig/article/details/75050398...原创 2019-02-19 11:30:51 · 159 阅读 · 0 评论 -
C++课堂笔记整理(STL) set 5
#include <iostream>#include <functional>using namespace std;#include "set"void main95(){ set<int> set1; for (int i = 0; i < 10; i++) { set1.insert(i+1); } //从大到小 f...原创 2019-02-13 11:07:02 · 177 阅读 · 0 评论 -
C++课堂笔记整理(STL)multiset
#include <iostream>using namespace std;#include "set"void main1001(){ multiset<int> set1; int tmp = 0; printf("请输入multiset集合的值:"); scanf_s("%d", &tmp); while (tmp != 0) ...原创 2019-02-13 12:53:34 · 164 阅读 · 0 评论 -
C++课堂笔记整理(STL) map1
#include <iostream>using namespace std;#include "map"#include "string"//map元素的添加、遍历、删除基本操作void main1101(){ map<int, string> map1; //方法1 map1.insert(pair<int,string>(1,"t...原创 2019-02-13 15:09:44 · 174 阅读 · 0 评论 -
C++课堂笔记整理(STL) map2
#include <iostream>using namespace std;#include "map"#include "string"void main1101(){ map<int, string> map1; //方法1 map1.insert(pair<int,string>(1,"teacher01")); map1.i..原创 2019-02-13 15:36:40 · 212 阅读 · 0 评论 -
P33_字符串的基本操作
#include <iostream>#include <string>using namespace std;//字符串//1 C语言的字符串 以零结尾的字符串//2 在C语言中没有字符串类型 通过字符数组 来模拟字符串//3 字符串的内存分配 堆上 栈上 全局区(很重要)void main51(){ //1 指定长度 char buf...原创 2019-02-24 14:19:54 · 124 阅读 · 0 评论 -
C++ 多态01
1、多态:相同的消息传给不同的对象,产生了“不同形式的结果”。//它是将派生类对象视为基类对象,并执行派生类的Swim()实现//为了实现上述目的,需要把FIsh::Swim() 声明为虚函数,//从而使派生类Tuna::Swim()和Crap::Swim()优先于被声明为虚函数的FIsh::Swim(),即进行覆盖#include <iostream>usi...原创 2019-02-19 10:35:39 · 149 阅读 · 0 评论 -
大学生C++教程第九版 习题(10.8)
#include <iostream>#include <string>#include <iomanip>using namespace std;int main(){ int i=1; cout << "N" << setw(12) << "10*N" <&l原创 2019-03-05 14:57:41 · 962 阅读 · 0 评论 -
C++课堂笔记整理(STL) set 1
#include <iostream>#include <string>using namespace std;#include "map"//Multimap 案例://1个key值可以对应多个value = 分组//公司有销售部 sale (员工2名)、技术研发部 development (1人)、财务部 Financial (2人)//人员信息...原创 2019-02-13 16:25:09 · 163 阅读 · 0 评论 -
P211_成员函数和友元函数完成一元运算符重载
#include <iostream>using namespace std;class Complex{ friend Complex& operator++(Complex &c1);private: int a; int b;public: Complex& operator--() { this->a--; this...原创 2019-02-20 15:43:40 · 222 阅读 · 0 评论 -
P212 成员函数和友元函数完成一元运算后置++和后置 - -
#include <iostream>using namespace std;class Complex{ friend Complex& operator++(Complex &c1); friend Complex operator++(Complex &c1, int);private: int a; int b;public: C...原创 2019-02-20 16:27:19 · 392 阅读 · 0 评论 -
C++ 错误贴
1、leafYear(m_year)==0错误原因,leafYear(m_year)本身就可以进行判断。原创 2019-03-24 21:10:07 · 137 阅读 · 0 评论 -
大学生C++教程第九版 习题(9.9)
//DateAndTime.h#ifndef DATEANDTIME_H#define DATEANDTIME_H#include <iostream>#include <iomanip>#include <stdexcept>#include <array>using namespace std;class DateAndTime...原创 2019-03-24 21:18:39 · 2042 阅读 · 0 评论 -
大学生C++教程第九版 习题(9.7)
//头文件#ifndef TIME_H#define TIME_H#include <iostream>#include <iomanip>#include <array>using namespace std;class Time{public: Time(int,int,int); ~Time(); void setTime(int...原创 2019-03-24 21:29:08 · 1871 阅读 · 0 评论 -
大学生C++教程第九版 习题(9.9)-继承
//头文件 Date.h#ifndef DATE_H#define DATE_H#include <iostream>#include <array>using namespace std;class Date{public: explicit Date(int, int, int); ~Date(); void setDate(int, in...原创 2019-03-24 22:22:19 · 369 阅读 · 1 评论 -
error C4996解决办法
解决博文:https://blog.youkuaiyun.com/dan15188387481/article/details/49622783/原创 2019-03-23 18:54:55 · 325 阅读 · 0 评论 -
大学生C++教程第九版 习题(9.4)
(增强的Time类)请提供一个构造函数,它可以用来自time函数和localtime函数的当前时间初始化Time类的对象。这两个函数在C++标准库头文件<ctime>中声明。#define _CRT_SECURE_NO_WARNINGS#include "Time.h"int main(){ //获取当前时间 time_t rawtime; struct tm ...原创 2019-03-23 19:07:13 · 2781 阅读 · 2 评论 -
大学生C++教程第九版 习题(9.8)
//头文件 Date.h#ifndef DATE_H#define DATE_H#include <iostream>#include <array>using namespace std;class Date{ public: explicit Date(int,int,int); ~Date(); void setDate(int, i...原创 2019-03-23 20:24:33 · 792 阅读 · 0 评论 -
大学生C++教程第九版 习题(4-34) 求阶乘
用C++计算e^x的值,公式:e^x=1+x/1!+x^2/2!+x^3/3!+...#include <iostream>using namespace std;double f(int);int main(){ double n; double total = 1; double mult=1; double x; cout << "输入...原创 2019-03-12 16:28:37 · 812 阅读 · 0 评论 -
大学生C++教程第九版 习题(4.25)
#include <iostream>using namespace std;void allStar(int);void spaceStar(int);int main(){ int n,i; cout << "请输入边长n:" << endl; cin >> n; for (i = 0; i < n; i++) {...原创 2019-03-12 15:00:39 · 194 阅读 · 0 评论 -
大学生C++教程第九版 习题(3_14)
#ifndef INVOICE_H#define INVOICE_H#include <iostream>#include <string>using namespace std;class Invoice{public: Invoice(string,string,int,int); ~Invoice(); void setNum(int); vo...原创 2019-03-11 10:36:18 · 843 阅读 · 0 评论 -
大学生C++教程第九版 习题(15_23)
#include <iostream>#include <array>using namespace std;#include <vector>bool decide1(vector<int> &integers2); //失误,缺少声明 “找不到标识符”int main(){ const size_t size...原创 2019-03-06 18:15:20 · 337 阅读 · 0 评论 -
P222 _()运算符重载
#include <iostream>using namespace std;class F{public: int operator()(int a, int b) { return (a*a + b*b); } };class F2{public: int MemFunc(int a, int b) { return a*a + b*b...原创 2019-02-20 22:04:08 · 146 阅读 · 0 评论 -
P185 深拷贝和浅拷贝
1 浅拷贝 复制类的对象时,将复制其指针成员,但不复制指针指向的缓冲区,其结果是两个对象指向同一块动态分配的内存。销毁其中一个对象时,delete[]释放这个内存块,导致另一个对象存储的指针拷贝无效。这种复制被称为浅复制,会威胁程序的安全性。//浅拷贝示意图//实例#define _CRT_SECURE_NO_WARNINGS#include <iostre...原创 2019-02-21 11:22:36 · 266 阅读 · 0 评论 -
C++的头文件
<iomanip> : 头文件中声明了参数化流操纵符(例如setw和setprecision)用于向格式化I/O提供有用服务。<fstream> : 头文件声明了文件处理服务。<stdexcept> :头文件中定义的标准异常类<functional> : 定义了一些模板类,用以声明函数对象<numeric...原创 2019-03-07 20:18:03 · 213 阅读 · 0 评论 -
函数对象笔记整理
函数对象: 重载函数调用操作符的类,其对象常称为函数对象。(function object)。 这是通过重载类的operator() 来实现。 在标准库中,函数对象被广泛使用以获得弹性,标准库中的很多算法都可以使用函数对象或者函数作为自定义的回调行为。谓词:谓词是一种特殊的函数对象,它的返回值是bool型。一...原创 2019-03-09 09:06:12 · 136 阅读 · 0 评论 -
大学生C++教程第九版 习题(7.10)
#include <iostream>using namespace std;#include <array>int& compute(int &fsale, int &ftotal);int main(){ int total = 0, sale = 0; size_t i = 0; array<int, 11&g...原创 2019-03-04 12:45:47 · 556 阅读 · 0 评论 -
大学生C++教程第九版 习题(3.12)
#ifndef ACCOUNT_H#define ACCOUNT_H#include <iostream>#include <string>using namespace std;class Account{public: explicit Account(int ); ~Account(); void setMoney(int); int g...原创 2019-03-11 09:39:14 · 590 阅读 · 3 评论