60. 函数综合运用

60. 函数综合运用

语法讲解 今天学: 多个函数可以互相配合完成任务。 #include <iostream> using namespace std; int square(int x) { re

阅读更多 →
59. 有返回值的函数

59. 有返回值的函数

语法讲解 今天学: 函数可以用 return 返回一个值。 #include <iostream> using namespace std; int add(int a, int b)

阅读更多 →
58. 带参数的函数

58. 带参数的函数

语法讲解 今天学: 函数可以接收参数,参数写在括号里。 #include <iostream> using namespace std; void say_hi(int n) {

阅读更多 →
57. 第一个函数

57. 第一个函数

语法讲解 今天学: 可以自己定义函数来封装一段逻辑,然后在 main 中调用。 #include <iostream> using namespace std; void greet()

阅读更多 →
56. 统计 vector 中的偶数

56. 统计 vector 中的偶数

语法讲解 今天学: 遍历容器时可以加条件判断来统计。 #include <iostream> #include <vector> using namespace std; i

阅读更多 →
55. 范围 for 遍历

55. 范围 for 遍历

语法讲解 今天学: C++ 的范围 for(for-each)可以方便地遍历数组或 vector。 #include <iostream> #include <vector>

阅读更多 →
54. push_back 添加元素

54. push_back 添加元素

语法讲解 今天学: push_back 可以在 vector 末尾添加新元素。 #include <iostream> #include <vector> using name

阅读更多 →
53. vector 求和

53. vector 求和

语法讲解 今天学: 遍历 vector 时可以把所有元素加起来。 #include <iostream> #include <vector> using namespace s

阅读更多 →
52. vector 容器

52. vector 容器

语法讲解 今天学: vector 是 C++ 的动态数组,需要 #include <vector>。可以用 {} 初始化。 #include <iostream> #inclu

阅读更多 →
51. 数组声明与遍历

51. 数组声明与遍历

语法讲解 今天学: 数组可以存多个同类型的值,用下标访问,下标从 0 开始。 #include <iostream> using namespace std; int main() {

阅读更多 →