
C++
黄皮大仙
游戏开发爱好者
展开
-
C++联合体与结构体
>>>>>都是xx体,分别理解一下。结构体struct// 定义一个结构体的结构,可以理解成这是一个自定义的类型typedef struct Role{ int HP; int MP;}*PRole;// 定义一个指针的PRole,用指针操作,可以节约大量的内存。因为使用实体需要分配内存空间int main(){ Role user;// 定义一个结构体实体 user PRole puser = &user;//原创 2021-09-25 09:49:46 · 359 阅读 · 0 评论 -
C++之string字符串
>>>>>需要引入#include <string>#include <iostream>#include <string>int main(){ /* * 特点: * 1.不存在内存溢出 * 2.本质是对char的封装 */ std::string str1{ "我是string字符串" }; std::string str2{ "666" }; std::string str3 = str1 + str2;原创 2021-09-22 22:40:49 · 406 阅读 · 0 评论 -
C++之指针
>>>>>对c++指针的理解: int* a{}, b;// a是指针,b是Int。别这么写,会增加理解成本。 int c = 2000; int* pc = &c;// 把c的地址赋值给pd,&是取址运算符。指针命名一般用p开头。pc表示c的内存地址 *pc = 500;// 表示在c的内存地址写入500,本质:c = 500; //32位系统地址大小0-2^32,64位系统地址大小0-2^64。 sizeof(pc);// 指针pc的内原创 2021-09-20 15:55:08 · 209 阅读 · 0 评论 -
C++之数组
>>>>>记录一些对C++数组的理解。原生数组特点:不安全,但速度快// 定义int arr[2];// 一维数组int arr[2][2];// 二维数组,尽量不要超过二维数组 否则会增加理解成本// 举例// 一维数组int studentid[] {10001, 10002, 10003, 10004, 10005};// 二维数组,尽量不要超过二维数组 否则会增加理解成本int studentId[2][5]{ [原创 2021-09-16 22:50:47 · 145 阅读 · 0 评论 -
C++之for循环
>>>>>记录几种常用for循环// 循环for(变量类型 变量名称:数组) 循环内容;for(auto 变量名称:数组) 循环内容;int studentid[] { 10001, 10002, 10003, 10004, 10005 };for (int value: studentid) std::cout << value << std::endl;// 注意:value就是值,不是下标!for (原创 2021-09-16 21:13:08 · 382 阅读 · 0 评论 -
C++之char字符
>>>>>笔记#include <iostream>// 所有以#号开头的,都是预处理文件【理解:引入此文件】int main(){ std::cout << "HelloWorld!" << std::endl;// 输出一个字符串 char char_test{ 'A'};// 占1字节 char_test++;// 得到 B std::cout << "你输入的内容:" <&原创 2021-09-16 21:09:11 · 691 阅读 · 0 评论 -
变量的生命周期
>>>>>以一对大括号{}为一个代码块,到达括号}时,变量生命周期结束举例:int a = 0;// main函数开始时产生。全局变量,生命周期特别长。【生命周期:main{开始到}结束,如果main使用了cout等关键字则长期存在】int main(){ int a = 1;// 到main函数的}时结束 { int a = 2; { int a = 3; { char a = 'A'; } std::cout &原创 2021-09-13 00:30:40 · 279 阅读 · 0 评论 -
c++命名空间
>>>>>理解:就是一个仓库,放命名的地方。// 自定义命名空间namespace game_test { int HP = 100; int MP = 100; namespace weapon { int atttack = 100; }}game_test::HP = 200;// 使用game_test::weapon::atttack = 200;// 使用规则:>>>>>...原创 2021-09-13 00:28:32 · 141 阅读 · 0 评论 -
运算优先级
>>>>>上图:>>>>>原创 2021-09-13 00:26:44 · 170 阅读 · 0 评论 -
C++基本数据类型
>>>>>常用类型举例: using namespace std: #define NUM "666666666"// 预定义 #define ADD(x, y) ((x) + (y));// 预定义 int num = 666;// 整数 int num1{ 666 }, num2{ 777 }, num3{ 888 };// 整数 double d_num = 66.66;// 小数 float f_num = 66.66; char c_cha原创 2021-09-11 21:59:32 · 226 阅读 · 0 评论 -
iostream理解
>>>>>// 输入输出流 || io流#include <iostream>// in(输入) out(输出) stream(流)int main(){ std::cout << "HelloWorld!" << std::endl;;// 打印且换行 printf("string");// 打印 system("pause");// 暂停 system("cls");// 清除屏幕 理解:clear screen原创 2021-09-11 12:26:51 · 410 阅读 · 0 评论 -
C++初体验
>>>>>前提:安装了vs编辑器,勾选使用c++开发的桌面应用,勾选v142生成工具,勾选window10最新sdk,新建项目:控制台程序。你好,世界#include <iostream>// 所有以#号开头的,都是预处理文件【理解:引入此文件】// #include 引入后面的文件// iostream是标准库文件,使用std命名空间时需要引入int main(){ std::cout << "HelloWorld!原创 2021-09-11 12:21:29 · 311 阅读 · 0 评论