自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(16)
  • 资源 (1)
  • 收藏
  • 关注

原创 虚函数的由来(详解见注释)

#include <iostream>using namespace std;//军队class Troops{public: virtual void fight(){ cout << "Strike back!" << endl; }};//陆军class Army :public Troops{public: void fight(){ cout << "--Army is figthing!" << endl; }

2022-02-18 09:47:27 139

原创 遍历目录树

https://blog.csdn.net/weixin_45782925/article/details/105790519if ((hFile=_findfirst(filespec,&fileinfo)) != -1)if ((hFile=_findfirst(".",&fileinfo)) != -1)

2022-02-17 16:21:59 226

原创 宏定义与内联函数

宏定义:#include <iostream>2. using namespace std;3.4. #define SQ(y) ((y)*(y))5.6. int main(){7. int n, sq;8. cin>>n;9. sq = SQ(n+1);10. cout<<sq<<endl;11. return 0;12. }内联函数:using namespace std;inline int SQ(int y){ re

2021-11-26 00:36:20 568

原创 内联函数与宏定义区别

宏定义是对字符串的替换,所以在使用时要非常谨慎,如经典程序:#include <iostream>#include<stdlib.h>using namespace std;#define SQ(y) ((y)*(y))int main(){ int n, sq; cin >> n; sq = 200 / SQ(n + 1); cout << sq << endl; system("pause"); return 0;

2021-11-26 00:28:37 470

原创 动态内存分配

c语言:int *p = (int *)malloc(sizeof(int)*10);//分配10个int型的内存空间free( p ) ;//释放内存c++:int *p = new int;//分配1个int型的内存空间delete p;//释放内存int *p = new int(2);//分配1个int型的内存空间,并初始化delete p;int *p = new int[10];//分配10个int型的内存空间delete[] p;...

2021-11-25 22:48:57 177

原创 extern的区别

普通全局变量的作用域是当前文件,在一个文件中定义,在另一个文件中声明一下不定义就可以直接用源文件1#include<stdio.h>#include<stdlib.h>int n = 10;void func();int main(){ func(); printf("main:%d\n", n); system("pause"); return 0;}源文件2#include<stdio.h>extern int n;void fu

2021-11-25 22:32:32 73

原创 布尔类型bool

c语言#include<stdio.h>#include<stdlib.h>int main(){ int a, b, flag; scanf_s("%d %d", &a, &b); flag = a > b;//flag保存关系运算结果 printf("flag = %d\n",flag); system("pause"); return 0;}c++#include<iostream>#include<stdli

2021-11-25 21:49:48 94

原创 for循环中定义变量

#include <iostream>#include <stdlib.h>using namespace std;int sum(int n){ int total = 0; //在for循环的条件语句内部定义变量i for (int i = 1; i <= n; i++){ total += i; } return total;}int main(){ cout << "Input a interge:"; int n; cin

2021-11-25 21:27:18 2754

原创 cin和cout

1.简单的输入输出代码示例:#include<iostream>#include<stdlib.h>using namespace std;int main(){ int x; float y; cout << "please input an int number:" << endl; cin >> x; cout << "The int number is X = " << x << end

2021-11-25 21:20:02 286 2

原创 命名空间namespace

#include <stdio.h>#include <stdlib.h>//将类定义在命名空间中namespace Diy{ class Student{ public: char *name; int age; float score; public: void say(){ printf("%s的年龄是%d,成绩是%f\n", name, age, score); } };}int main(){ Diy::Student st

2021-11-25 16:31:03 373

原创 结构体与类的区别

结构体:#include<stdio.h>#include <stdlib.h>//定义结构体 Studentstruct Student{ //结构体包含的成员变量 char *name; int age; float score;};//显示结构体的成员变量void display(struct Student stu){ printf("%s的年龄是%d,成绩是%f\n", stu.name, stu.age, stu.score);}int ma

2021-11-25 15:59:54 52

原创 头文件中< >与“ ”,加不加.h的区别

c++中囊括了c,所以区分一下c和c++的语法很有必要< >:表示引用标准头文件,头文件是系统路径" ":表示使用自己写的头文件,先从当前文件夹中找,找不到再从系统库环境中找加.h:编程时不用再加命名空间不加.h:编程时要加上命名空间...

2021-11-23 08:49:00 534

原创 命名空间 namespace

相比c语言,c++中引入了命名空间的概念就是我们经常看到的namespace我们以一个代码片段来讲解使用Li::#include "stdio.h"#include "stdlib.h"namespace Li{ class Student{ public: char *name; int age; int score; void display(){ printf("%s,%d,%d", name, age, score); } };}int main(

2021-11-20 11:26:28 455

原创 结构体与类的区别

结构体与类都是各种数据类型的集合,区别是结构体里只能是各种变量类型的集合,而类除了各种变量类型外,还可以有各种函数结构体举例:#include "stdio.h"#include "stdlib.h"struct Student{ char *name; int age; int score;};void display(struct Student stu){ printf("%s,%d,%d", stu.name, stu.age, stu.score);}int main

2021-11-20 10:31:20 440

原创 常量指针与指针常量

常量指针指向常量的指针,指针指向可以变,指针不能变const char *p = “csdn”;p=“msdn”;//是对的*p=“msdn”//是错的指针常量指针是常量,指针不能变,指针指向可以变char * const p = “csdn”p=“msdn”;//是错的,指针只能指向“csdn”*p=“msdn”//是对的指针即p指针指向即*p...

2021-11-19 22:09:02 171

原创 指针数组与数组指针

指针是与关键字组合,有许多用法,在此记下,供自己理解整型数组: int arr[] = {1,2,3,4 };字符数组: char str[] = “csdn”;数组指针: 整型数组指针: int arr[] = {1,2,3,4 };int *p = arr;字符型数组指针: char str[] = “csdn”;char *p = str;指针数组: 整型指针数组: int a,b,c,d;int arr[ ] = {&a,&b,

2021-11-18 23:52:23 334

遍历目录树 遍历目录树 遍历目录树 遍历目录树

遍历目录树 遍历目录树 遍历目录树 遍历目录树

2022-02-17

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除