C++
文章平均质量分 57
读书札记2022
这个作者很懒,什么都没留下…
展开
-
C++ lambda表达式
Lambda 表达式可以捕获外部变量。:匿名函数是一个广泛的概念,用于描述没有名字的函数,Lambda 表达式是一种特定的匿名函数实现。在许多编程语言中,Lambda 表达式可以捕获外部变量的上下文(即闭包),而传统的匿名函数则不总是具备这种能力。6、值得注意的是,如果不使用按引用捕获外部变量的方式,但也想修改外部变量,可以使用 mutable 关键字,但是。:Lambda表达式使得可以在需要函数作为参数的情况下,快速定义函数,而不需要事先声明一个函数。parameters:参数列表,与普通函数类似。原创 2025-02-24 21:24:06 · 351 阅读 · 0 评论 -
Acutest 的介绍和使用
4、运行:因为头文件acutest.h中提供了程序入口点(main() 函数),因此直接运行程序即可,但大概率会碰到控制台窗口闪退的问题,这样就看不到单元测试的结果了,因此我们需要用可执行程序来运行。3、头文件acutest.h中提供了程序入口点(main() 函数),因此自己的程序中不能再编写main() 函数。2、无需安装/设置/配置任何测试框架,Acutest 只是一个单一的头文件,即 acutest.h;1、Acutest 是一个 C/C++ 单元测试工具;原创 2025-02-10 22:13:18 · 325 阅读 · 0 评论 -
C++基础之结构体中const的使用场景
说明:用const来防止误操作。#include <iostream>using namespace std;#include<string>struct Student{ string name; int age; int score;};void printStudents(const struct Student *s1){ //s1->age = 19;//编译报错,因为形参有const修饰所以不可修改,只能打印(读) cout <原创 2020-07-05 22:23:55 · 346 阅读 · 0 评论 -
C++基础之结构体做函数参数
说明:将结构体作为参数向函数中传递有值传递和地址传递两种方式。#include <iostream>using namespace std;#include<string>struct Student{ string name; int age; int score;};/* 1.值传递*/void printStudent1(struct Student s1){ cout << s1.name << s1.age <原创 2020-07-04 17:55:38 · 382 阅读 · 0 评论 -
C++基础之结构体嵌套结构体 实例
实例:老师辅导学生#include <iostream>using namespace std;#include<string>/* 定义学生和老师两个结构体*/struct Student{ string name; int age; int score;};struct Teacher{ int id; string name; int age; struct Student s1;};int main() { struct T原创 2020-07-04 17:19:26 · 678 阅读 · 0 评论 -
C++基础之结构体指针
结构体指针:通过指针访问结构体中的成员。具体实现:#include <iostream>using namespace std;#include<string>/* 定义一个结构体*/struct Student{ string name; int age; int score;};int main() { /* 创建结构体变量 */ struct Student s1 = {"小红",12,68}; /* 指针指向结构体变量 *原创 2020-07-04 16:55:32 · 348 阅读 · 0 评论 -
C++基础之结构体数组
结构体数组:将自定义的结构体放入到数组中方便维护。#include <iostream>using namespace std;#include<string>/* 定义一个结构体*/struct Student{ string name; int age; int score;};int main() { /* 创建结构体数组并赋值 */ struct Student stuArray[3] = { {"小明",19,60},原创 2020-07-04 10:41:36 · 559 阅读 · 0 评论 -
C++基础之结构体的定义和使用
一.结构体的基本概念结构体属于用户自定义的数据类型,允许用户存储不同的数据类型。二.具体使用#include <iostream>using namespace std;#include<string>/* 声明结构体*/struct Student{ string name; int age; int score;};int main() { /* 赋值并使用方式一 */ struct Student s1;//定义结构体类型变量s1原创 2020-07-04 08:34:08 · 746 阅读 · 0 评论 -
C++基础之地址传递+数组冒泡排序实例
关键点:向函数传入数组首地址#include <iostream>using namespace std;/* 冒泡排序*/void bubbleSort(int *arr,int length){ for (int i = 0; i < length - 1; i++) { for (int j = 0; j < length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { int temp原创 2020-07-03 15:15:01 · 573 阅读 · 0 评论 -
C++基础之利用指针作函数的参数修改实参的值 地址传递
#include <iostream>using namespace std;/* 地址传递,可以修改实参的值*/void swap(int *p1, int *p2){ int temp = *p1; *p1 = *p2; *p2 = temp; }int main() { int a = 10; int b = 20; swap(&a, &b); cout << "a=" << a << endl;原创 2020-07-03 14:47:09 · 524 阅读 · 0 评论 -
C++基础之利用指针访问数组中的元素
关键点:拿到数组首地址。#include <iostream>using namespace std;int main() { int arr[] = { 1,2,3,4,5,6,7,8,9,10 }; int *p = arr;//数组名就是数组首地址 cout << "第一个元素:" << arr[0] << endl;//1 cout << "指针访问第一个元素:" << *p << endl;/原创 2020-07-03 10:47:40 · 1457 阅读 · 0 评论 -
C++指针基础之const修饰指针
一.const修饰指针有三种情况:1.const修饰指针:常量指针2.const修饰常量:指针常量3.const既修饰指针又修饰常量二.特点:常量指针:指针的指向可以修改,但是指针指向的值不可以修改。 int a = 20; const int *p = &a;//常量指针指针常量:指针的指向不可以修改,但是指针指向的值可以修改。 int a = 20; int * const p = &a;//指针常量const既修饰指针又修饰常量:指针的指向和指针指向的值都原创 2020-07-03 10:04:23 · 201 阅读 · 0 评论 -
C++基础之函数的分文件编写
一.步骤:1.创建.h后缀名的头文件2.创建.cpp后缀名的源文件3.在头文件中写函数的声明4.在源文件中写函数的定义二.具体实现:1.头文件—>添加—>新建项:2.名称改为以.h为后缀名,然后点击添加按钮...原创 2020-07-02 17:50:31 · 542 阅读 · 0 评论 -
C++数组基础之二维数组名
二维数组名的作用:1.查看二维数组所占内存空间。2.获取二维数组首地址。原创 2020-06-29 07:55:15 · 363 阅读 · 0 评论 -
C++数组基础之二维数组定义方式
第一种方式: /* 推荐使用:可读性更强 */ int arr[2][3] = { {1,2,3}, {4,5,6} };第二种方式: int arr[2][3]; arr[0][0] = 1; arr[0][1] = 2; arr[0][2] = 3; arr[1][0] = 4; arr[1][1] = 5; arr[1][2] = 6;第三种方式: int arr[2][3] = { 1,2,3,4,5,6 };第四种方式: /* 可以只写列原创 2020-06-28 20:31:56 · 775 阅读 · 0 评论 -
C++数组基础之一维数组名
一维数组名的作用:1.可以统计整个数组在内存中的长度。2.可以获取数组在内存中的首地址。3.数组名是常量,不可以进行赋值操作。#include <iostream>using namespace std;int main() { /* 1.int占4个字节(32位机器) 2.一个字节等于八位 */ int arr[5] = { 1,2,3,4,5}; cout << "整个数组占用内存空间为:" << sizeof(arr) <&l原创 2020-06-26 22:37:35 · 333 阅读 · 0 评论 -
C++循环语法基础之打印标准的九九乘法口诀表
#include <iostream>using namespace std;int main() { for (int i = 1; i <=9; i++) { for (int j = 1; j <= i; j++) { cout << j << "*" << i << "=" << i * j<<"\t";//使用制表符\t对齐输出位置 } cout << en原创 2020-06-25 21:43:52 · 911 阅读 · 0 评论 -
C++基础之随机数函数 猜数字小游戏 生成1-100之间的随机数
#include <iostream>using namespace std;/*rand()%100:生成0-99之间的随机数*/int main() { int num1 = rand() % 100 + 1;//生成1-100之间的随机数 int num2; cin >> num2; while (num1 != num2) { if (num1 > num2) { cout << "猜小了" << e原创 2020-06-24 21:53:01 · 11428 阅读 · 1 评论 -
C++基础之字符串的简单使用
说明:C++中可以使用两种不同的风格表示字符串。第一种风格:#include <iostream>using namespace std;int main() { char str[] = "123abc"; cout << str << endl;//输出123abc system("pause"); return 0;}第二种风格:#include <iostream>using namespace std;#incl原创 2020-06-24 15:21:13 · 204 阅读 · 0 评论
分享