随笔分类 -  C/C++

摘要:目的 假设有这一个需求。 去重复并获取独立部分 例如下面两个 1.字符串"1233214" → "4" 2.字符串数组{ "1","2","3","3","2","1","4" } → { "4" } 很直白,不多说。 上代码 完整代码 #include <iostream> #include <s 阅读全文
posted @ 2021-12-15 16:52 想想就很离谱 阅读(343) 评论(0) 推荐(0)
摘要:前言 用C语言实现一个图书管理系统 简单的那种。 简单 。 运行环境:vs2013 效果 1.主界面 2.查看库存 3.录入书籍 4.删除书籍 5.查询书籍 6.价格排序 7.修改信息 8.退出 完整代码 /************************************** * Autho 阅读全文
posted @ 2021-12-15 14:37 想想就很离谱 阅读(1658) 评论(0) 推荐(1)
摘要:背景 有以下需求 1.假设我们只知道 A 的地址,struct1 的地址是不知道的 2.那么如何通过 A 的地址去找到 struct1 的地址呢? #include <stdio.h> typedef struct MyStruct1 { int a ; char b ; int c ; } Str 阅读全文
posted @ 2021-12-14 21:02 想想就很离谱 阅读(566) 评论(0) 推荐(0)
摘要:目的 玩点花哨儿的东西 通过函数指针寻址到另一个函数地址并调用 上代码 #include <stdio.h> typedef void(*Type)(); // 测试函数1 void Fun1() { printf("I am Fun1\n"); } // 测试函数2 void Fun2() { p 阅读全文
posted @ 2021-12-14 17:57 想想就很离谱 阅读(288) 评论(0) 推荐(0)
摘要:要求 用C语言判断某年某月是否为闰年该月有多少天。 判断是否闰年满足以下其中一个条件即可 1.该年份能被 4 整除同时不能被 100 整除。 2.该年份能被400整除。 上代码 #include <stdio.h> // 主函数 int main(int argc, char **argv) { i 阅读全文
posted @ 2021-12-14 17:04 想想就很离谱 阅读(394) 评论(0) 推荐(0)
摘要:要求 用C语言打印9x9乘法表 上代码 #include <stdio.h> // 打印99乘法表 void printMultiplication99() { for (int i = 1; i <= 9; ++i) { for (int j = 1; j <= i; ++j) { printf( 阅读全文
posted @ 2021-12-14 15:51 想想就很离谱 阅读(178) 评论(0) 推荐(0)
摘要:要求 用C语言打印一个菱形图案。 上代码 #include <stdio.h> // 打印菱形 void printRhombus(int N) { /// 1.上三角形 for (int n = 1; n <= N; ++n) { // 1.打空格 for (int i = 0; i < N - 阅读全文
posted @ 2021-12-14 15:09 想想就很离谱 阅读(1229) 评论(0) 推荐(0)
摘要:要求 C语言比较三个数大小并求出最大最小值 上代码 #include <stdio.h> // 返回最大值 int compare1(int a, int b) { return a > b ? a : b; } // 返回最小值 int compare2(int a, int b) { retur 阅读全文
posted @ 2021-12-14 14:01 想想就很离谱 阅读(2642) 评论(0) 推荐(0)
摘要:要求 在忽略其他一些情况下,把整型 a 和 b 的值互换。 应该比较简单,直接上代码。 小二上代码 #include <stdio.h> // 主函数 int main(int argc, char **argv) { int a = 50; int b = 20; printf("交换前: a = 阅读全文
posted @ 2021-12-14 13:27 想想就很离谱 阅读(8874) 评论(0) 推荐(0)
摘要:要求 // 要求:将 str 中重复项去除 string str{"A1","A8","A2","A2","A8","A3","A1","A4"}; 小二上代码 #include <iostream> #include <string> #include <vector> #include <alg 阅读全文
posted @ 2021-12-14 11:18 想想就很离谱 阅读(555) 评论(0) 推荐(0)
摘要:前言 先上结论: ·成对使用 new 和 delete 时要采用相同形式 1.在 new 表达式中使用 [], 那么在 delete 中也要使用 [] 2.在 new 表达式中没有使用 [], 那么在 delete 中不要使用 [] 例如: string* a1 = new string; stri 阅读全文
posted @ 2021-09-10 15:46 想想就很离谱 阅读(195) 评论(0) 推荐(0)
摘要:前言 在调试程序的时候会使用一些打印函数进行辅助调试,在期间遇到一些平时没注意的事儿。 代码演示 #include <iostream> #include <stdio.h> using namespace std; int main(int arg, char** argv) { int n = 阅读全文
posted @ 2021-09-03 17:59 想想就很离谱 阅读(114) 评论(0) 推荐(0)
摘要:前言 假设有个数字1234,然后它怎么读数呢? 其中4是个位,3是十位,2是百位,1是千位。 也就是4是最低位,1是最高位。 也就是最左边是最高位,最右边是最低位。 回到主题,声明一个变量 int a = 0x12345678 因一个字节是8位,所以 12是一个字节。 34是一个字节。 56是一个字 阅读全文
posted @ 2021-07-22 15:27 想想就很离谱 阅读(482) 评论(0) 推荐(0)
摘要:背景 我们很多时候看到类似以下代码 int main(int argc, char **argv) { int value = 10; cout << value << endl; return 0; } 输出: 但如果我们自定义的类,是否也能这样的输出呢,看以下代码 很显然,这已经报错了 解决方法 阅读全文
posted @ 2021-07-05 22:44 想想就很离谱 阅读(424) 评论(0) 推荐(0)
摘要:前言 很多时候,我们会看到一些在创建对象时有的加括号有的不加括号 那么,这是什么情况呢? 我们来验证一下。 1.基本数据类型不带括号() #include <iostream> using namespace std; int main(int arg, char **argv) { int a; 阅读全文
posted @ 2021-07-05 22:38 想想就很离谱 阅读(1339) 评论(0) 推荐(0)