![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
ChrisKyrie
这个作者很懒,什么都没留下…
展开
-
多态与虚函数
例子1:#include <iostream>using namespace std;class Base{public: int val;public: Base(int n) :val(n) {}; virtual void changeVal() = 0;};class Derive1 :public Base{public: Derive1(int n = 0):Base(n){} virtual void changeVal() { th原创 2020-10-06 10:44:37 · 80 阅读 · 0 评论 -
C++单例类
单例类:#include <iostream>#include <map>#include <array>#include <memory>#include <vector>using namespace std;class SingleClass{private: SingleClass() {}; //析构函数必须是privateprivate: static SingleClass *sc; // 定义原创 2020-09-27 10:46:00 · 970 阅读 · 0 评论 -
c++11新特性
c++11新特性,所有知识点都在这了!后端技术学堂5月27日以下文章来源于程序喵大人,作者程序喵大人程序喵大人分享计算机基础及高端知识,主要有C++、java、Android、音视频、数据结构、操作系统、计算机网络、深度学习等。c++程序员面试过程中基本上都会被问到c++11新特性吧,你是怎么回答的呢?本文基本上涵盖了c++11的所有新特性,并有详细代码介绍其用法,对关键知识点做了深入分析,对重要的知识点我单独写了相关文章并附上了相关链接,我整理了完备的c++新特性脑图(由于..原创 2020-07-03 17:05:37 · 323 阅读 · 0 评论 -
奇怪的问题
int main(){ map<string, int> map1; for (int i = 0; i < 10; i++) { string s = "Map" + to_string(i); map1[s] = i; } for (auto it : map1) { cout << it.first << " " << it.second << endl; }}原创 2020-06-16 21:18:06 · 141 阅读 · 0 评论 -
C++通过stringstream实现int与string之间的转化
#include <iostream>#include <string>#include <sstream>using namespace std;int main(){ stringstream stream; string s; int n; //string转int getline(cin, s); stream << s; stream >> n; //int转s.原创 2020-06-10 20:54:50 · 465 阅读 · 0 评论 -
C++中map按照value排序
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <fstream>#include <map>#include <queue>#include <stack>#inclu...原创 2020-04-15 20:18:48 · 1111 阅读 · 0 评论 -
C++两个statck实现queue
#include <iostream>#include <queue>#include <stack>using namespace std;class MyQueue{private: stack<int> s1; stack<int> s2;public: MyQueue(); void pop();...原创 2020-04-13 22:20:04 · 182 阅读 · 0 评论 -
求两个数数中较大值与较小值
#include <iostream>using namespace std;int main(){ int a, b, maxVlaue, minVlaue; cin >> a >> b; maxVlaue = (a > b) * a + (a < b) * b; minVlaue = (a > b) * b + (a &l...原创 2020-02-23 10:26:40 · 1132 阅读 · 0 评论 -
Java和C++通过new创建的对象有何区别
Java和C++通过new创建的对象有何区别?更新时间:2017年11月17日 08:41:20 作者:Wray Zheng 我要评论Java和C++都是面向对象的编程语言,然而Java和C++在创建对象时却存在不同的方式,由于方式的不同导致在内存中管理的不同。这篇文章主要给大家介绍了关于Java和C++通过new创建对象区别的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧...原创 2019-11-30 11:29:45 · 121 阅读 · 0 评论 -
大数相加
在一些科学研究领域,常常会遇到很大的数字,比如:光年(1光年=9,460,730,472,580,800米) 当面对这些非常巨大的数字时,计算机内基础类型(如int,longlong,double等)就很难存储它们,并进行运算了,所以,现在需要你来解决这个问题。输入a和b,(a,b > 1020),输出a+b的结果输入:9234567880123, 1111111111111输出:1...原创 2019-11-28 16:18:04 · 118 阅读 · 0 评论 -
砝码问题
设有1g、2g、3g、5g、10g、20g的砝码各若干枚(其总重<=1000),求用这些砝码能称出不同的重量个数。输入1g、2g、3g、5g、10g、20g的砝码个数。输出能称出不同重量的个数。如输入:1 1 0 0 0 0输出:3#include "pch.h"#include <iostream>using namespace std;int main(...原创 2019-11-27 15:23:08 · 2129 阅读 · 0 评论 -
C++面向对象练习题6
#include "pch.h"#include "STR.h"#include <iostream>#include <string>#include <cstdlib>using namespace std;#pragma warning(disable:4996)class STR{private: char s1[80], s...原创 2019-10-15 11:11:17 · 356 阅读 · 0 评论 -
C++面向对象练习题3
#include "pch.h"#include "Array.h"#include <iostream>using namespace std;class Array{private: int *p, k; float *s;public: Array(int *ptr, int n); int fun(int n); void sum(); voi...原创 2019-10-15 10:32:29 · 209 阅读 · 0 评论 -
C++输入字符串以换行结束
#include "pch.h"#include <iostream>#include <string>using namespace std;int main(){ string str; getline(cin, str); cout << str << endl;}#include "pch.h"#include ...原创 2019-09-24 14:54:07 · 4532 阅读 · 0 评论 -
C++输出固定位数的小数
#include "pch.h"#include <iostream>#include <iomanip>using namespace std;int main(){ double num = 2.0; cout.setf(ios::fixed); cout << fixed << setprecision(2) <<...原创 2019-09-21 14:34:12 · 2116 阅读 · 0 评论 -
C++面向对象练习题3
题目:代码:#include "pch.h"#include <iostream>#include <string>using namespace std;class ID {private: char s[19]; char x[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3'...原创 2019-09-21 14:33:25 · 182 阅读 · 0 评论 -
C++面向对象练习题2
题目:代码:#include "pch.h"#include <iostream>using namespace std;class ARRAY {private: float a[10]; float b[10];public: ARRAY(float t[10]) { for (int i = 0; i < 10; i++) { ...原创 2019-09-21 10:23:40 · 318 阅读 · 0 评论 -
C++面向对象练习题1
题目描述:代码如下:#include "pch.h"#include <iostream>using namespace std;class Fract {private: int num; int den;public: Fract(){}; Fract(int a, int b); int ged(int m, int n); Fract ad...原创 2019-09-20 20:16:12 · 742 阅读 · 0 评论 -
vs获取系统时间
#include "pch.h"#include <iostream>#include <cmath>#include <cstring>#include <string>#include <ctime>using namespace std;int main(){ time_t curtime = time(NUL...原创 2019-08-14 16:05:24 · 1505 阅读 · 0 评论 -
c++中指定位数的浮点数输出
在C语言中输出小数位数代码如下:double a = 1.7569;printf("%.2lf\n", a);C++中如下:double a = 1.7569;cout << setiosflags(ios::fixed) << setprecision(3) << a << endl;参考博客:http://www.cnbl...原创 2019-04-04 09:49:28 · 2063 阅读 · 0 评论 -
链表实现多项式运算
#include <stdio.h>#include <stdlib.h>typedef struct ListNode{ int ratio; int expton; struct ListNode *next;}List;List *CreatList (){ List *e1, *e2, *L; L = NULL...原创 2018-05-04 15:24:39 · 769 阅读 · 0 评论 -
C语言文件写操作
#include #include void emcrpy(char *p){ if(*p != '\0') { *p = *p^15; p++; }}int main (){ FILE *fp; int i; char name[20], code[20]; if((fp = fopen("C:\\U原创 2018-01-13 14:11:08 · 165 阅读 · 0 评论 -
增量型PID算法
#include using namespace std;struct _PID{ float SetSpeed; float ActualSpeed; float Kp; float Ki; float Kd; float err; float Last_err; float Up_err; float PID_in原创 2017-12-11 10:37:50 · 1960 阅读 · 0 评论 -
位置型PID算法
#include using namespace std;struct _PID{ float SetSpeed; float ActualSpeed; float Kp; float Ki; float Kd; float err; float Last_err; float integral;}PID;void PI原创 2017-12-11 09:59:59 · 1886 阅读 · 0 评论 -
C语言中比较字符串大小
使用指针比较数组大小,编译器采用的是Code:Block。程序如下:#include using namespace std;int main (){ char table1[100], table2[100]; char *s1, *s2; s1 = table1; s2 = table2; int flag = 0;原创 2017-09-25 17:31:20 · 20655 阅读 · 0 评论 -
学生信息系统的c程序
#include using namespace std;struct mesg{ char name[10]; int year; char phone[20];};int main (){ int i, j; struct mesg lbn[5], temple;/*Input message*/ cout << "Enter原创 2017-10-10 13:50:02 · 293 阅读 · 0 评论 -
递归函数逆序输出程序
利用递归的思想,逆序输出一个整数#include using namespace std;void turn (int num);int main (){ int number; cout << "Enter a number:" ; cin >> number; turn (number);}void turn (int num){原创 2017-10-17 15:35:40 · 3556 阅读 · 1 评论 -
冒泡排序
#include using namespace std;int main (){ int table[5]; int temple = 0; for(int i = 0; i<5; i++) { cin >> table[i]; } for(int i = 0; i<5; i++) { for(int原创 2017-10-17 15:46:37 · 113 阅读 · 0 评论 -
用递归的思想求斐波那契数
#include using namespace std;int f (int x){ if(x<=1) return x; else { return f(x-2)+f(x-1); }}int main (){ int n; cin >> n; cout << f(n) << endl;原创 2017-10-19 16:26:48 · 397 阅读 · 0 评论 -
C语言文件复制操作
#include #include int main (){ FILE *fp1, *fp2; char ch; int num = 0; if((fp1 = fopen("C:\\Users\\lbn\\Desktop\\test.txt", "r")) == NULL) { printf("File1 open failed!\n原创 2018-01-13 14:24:32 · 2276 阅读 · 0 评论 -
C语言建立用户管理系统
#include #include #include typedef struct{ char username[20]; char userpassworld[20];}LOADSYSTEM;void encrypt (char *pwd){ while((*pwd) != '\0') { *pwd = *pwd^15;原创 2018-01-15 10:34:27 · 8183 阅读 · 3 评论 -
C++中sort函数的用法
最近在写程序时,当用到排序算法时,自己总是想通过自己编写诸如冒泡排序、快排等算法来实现排序。但是有些题目的重点不是排序,这往往浪费了自己的精力。通过C++中的sort函数,可以快速实现排序。sort函数的参数可以是两个,也可以是三个。sort(数据起始地址,数据结束地址,排序方式),其中排序方式可以是升序,也可以是降序,默认是升序。下面两个代码分别是升序和降序的例子。#include <st...原创 2018-03-30 08:11:43 · 778 阅读 · 0 评论 -
关于printf
今天无意中使用printf打印结果:int a = 2;printf("%d %d", a, a++);本来以为输出结果应该是:2 2;但是结果却是3 2;通过网上查资料发现。printf函数(所有的函数)参数的传递其实遵循栈的原则,通过从右向左压栈,然后再出栈的方式传递参数值。分析以上,a++,首先将a=2压栈,然后a自加1,即a=3,压栈。然后出栈,所以结果是3 2。通过这个例子,再次感觉到c...原创 2018-03-19 18:03:15 · 270 阅读 · 0 评论 -
产生在[x, y]的随机数
#include #include #include #define x 10#define y 15int main (){ int i; srand((int)time(0)); for(i = 0; i < 5; i++) { printf("%d\n", x+rand()%(y-x+1)); } return原创 2018-01-16 09:34:16 · 417 阅读 · 0 评论 -
C语言关键字static的用法
在C语言中static的用法主要有以下3种1、static用来修饰全局变量,那么全部变量只能在此文件中使用,在其他文件中使用会报错2、static用来修饰局部变量,那么此时的局部变量类似于全局变量的用法,初始化一次,每次调用的值是上一次的调用的结果。但是只能在局部函数中使用。3、static用来修饰函数,那么此函数只能在此文件中使用,在其他文件中使用会报错。原创 2018-01-15 14:29:15 · 167 阅读 · 0 评论 -
结构体数组应用
#include #include using namespace std;struct info{ char num[20]; char name[20]; int score;};int main (){ FILE *fp; int i, j; int sum_score = 0; struct info studen原创 2017-12-30 14:23:24 · 263 阅读 · 0 评论 -
C语言读取文件将大写字母转化为小写字母
#include #include #include int main (){ FILE *fp; char Filename[50], ch; int a = 0; printf("Enter PathName:"); scanf("%s", Filename); if((fp = fopen(Filename, "r")) == NUL原创 2018-01-15 11:28:42 · 5908 阅读 · 0 评论 -
函数指针
#include using namespace std;double f (double n);double fun (double(*funptr)(double), double a, double b);int main (){ double sum; sum = fun(f, 0.0, 1.0); cout << sum << endl; r原创 2017-10-20 14:21:37 · 120 阅读 · 0 评论