Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
applenob committed Dec 31, 2018
1 parent f8ba95d commit fbf71b7
Show file tree
Hide file tree
Showing 30 changed files with 58 additions and 62 deletions.
67 changes: 25 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,29 @@ C++ Primer 中文版第5版学习仓库,包括笔记和我的课后练习答

[原书第五版pdf链接](https://download.csdn.net/download/yjwffgip456/9448570)

## 笔记
## 目录

- [Chapter 1 开始](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch1.md)
- [Chapter 2 变量和基本类型](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch2.md)
- [Chapter 3 字符串、向量和数组](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch3.md)
- [Chapter 4](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch4.md)
- [Chapter 5](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch5.md)
- [Chapter 6](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch6.md)
- [Chapter 7](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch7.md)
- [Chapter 8](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch8.md)
- [Chapter 9](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch9.md)
- [Chapter 10](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch10.md)
- [Chapter 11](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch11.md)
- [Chapter 12](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch12.md)
- [Chapter 13](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch13.md)
- [Chapter 14](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch14.md)
- [Chapter 15](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch15.md)
- [Chapter 16](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch16.md)
- [Chapter 17](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch17.md)
- [Chapter 18](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch18.md)
- [Chapter 19](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch19.md)

## 练习

- [Chapter 1 开始](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch1.md)
- [Chapter 2 变量和基本类型](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch2.md)
- [Chapter 3 字符串、向量和数组](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch3.md)
- [Chapter 4](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch4.md)
- [Chapter 5](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch5.md)
- [Chapter 6](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch6.md)
- [Chapter 7](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch7.md)
- [Chapter 8](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch8.md)
- [Chapter 9](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch9.md)
- [Chapter 10](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch10.md)
- [Chapter 11](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch11.md)
- [Chapter 12](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch12.md)
- [Chapter 13](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch13.md)
- [Chapter 14](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch14.md)
- [Chapter 15](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch15.md)
- [Chapter 16](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch16.md)
- [Chapter 17](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch17.md)
- [Chapter 18](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch18.md)
- [Chapter 19](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch19.md)
- 第1章 : 开始 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch01.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch01.md)
- 第 I 部分 : C++基础
- 第2章 : 变量和基本类型 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch02.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch02.md)
- 第3章 : 字符串、向量和数组 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch03.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch03.md)
- 第4章 : 表达式 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch04.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch04.md)
- 第5章 : 语句 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch05.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch05.md)
- 第6章 : 函数 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch06.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch06.md)
- 第7章 : 类 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch07.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch07.md)
- 第 II 部分 : C++标准库
- 第8章 : IO库 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch08.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch08.md)
- 第9章 : 顺序容器 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch09.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch09.md)
- 第10章 : 泛型算法 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch10.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch10.md)
- 第11章 : 关联容器 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch11.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch11.md)
- 第12章 : 动态内存 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch12.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch12.md)
- 第 III 部分 : 类设计者的工具
- 第13章 : 拷贝控制 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch13.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch13.md)
- 第14章 : 重载与类型转换 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch14.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch14.md)
- 第15章 : 面向对象程序设计 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch15.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch15.md)
- 第16章 : 模版与泛型编程 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch16.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch16.md)
- 第 IV 部分 : 高级主题
- 第17章 : 标准库与特殊设施 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch17.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch17.md)
- 第18章 : 用于大型程序的工具 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch18.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch18.md)
- 第19章 : 特殊工具与技术 [笔记](https://github.com/applenob/Cpp_Primer_Practice/tree/master/notes/ch19.md) [练习](https://github.com/applenob/Cpp_Primer_Practice/tree/master/excersize/ch19.md)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions excersize/ch3.md → excersize/ch03.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ int main()

解:

- 类似`is >> s`的读取:string对象会忽略开头的空白并从第一个真正的字符开始,直到遇见下一空白为止
- 类似`getline(is, s)`的读取:string对象会从输入流中读取字符,直到遇见换行符为止
- 类似`is >> s`的读取:string对象会忽略开头的空白并从第一个真正的字符开始,直到遇见下一**空白**为止
- 类似`getline(is, s)`的读取:string对象会从输入流中读取字符,直到遇见**换行符**为止


## 练习3.4
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 12 additions & 1 deletion notes/ch1.md → notes/ch01.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- 查看运行状态:`echo $?`
- 编译多个文件:`g++ ch2.cpp Sales_item.cc -o main`

输入 `gcc --help`,查看编译器选项:

```
Usage: g++ [options] file...
Options:
Expand Down Expand Up @@ -66,11 +68,20 @@ Options:
```

输入 `gcc -v --help`可以看到更完整的指令。
例如还有些常用的:
```
-h FILENAME, -soname FILENAME: Set internal name of shared library
-I PROGRAM, --dynamic-linker PROGRAM: Set PROGRAM as the dynamic linker to use
-l LIBNAME, --library LIBNAME: Search for library LIBNAME
-L DIRECTORY, --library-path DIRECTORY: Add DIRECTORY to library search path
```

**获得程序状态**:
- windows: ``echo %ERRORLEVEL%``
- UNIX: ``echo $?``

## io
## IO

- ```#include <iostream>```
- ```std::cout << "hello"```
Expand Down
16 changes: 8 additions & 8 deletions notes/ch2.md → notes/ch02.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@
## 引用
- **引用**:引用是一个对象的别名,如`int &refVal = val;`
- 引用必须初始化。
- 引用和它的初始值是**绑定(bind)**在一起的,而不是拷贝。
- 引用和它的初始值是**绑定bind**在一起的,而不是拷贝。

## 指针
- 是一种 "指向(point to)"另外一种类型的复合类型。
- 定义指针类型`int *ip1;`**从右向左读**`ip1`是指向`int`类型的指针。
- 指针存放某个对象的地址
- 是一种 `"指向(point to)"`另外一种类型的复合类型。
- **定义**指针类型`int *ip1;`**从右向左读**`ip1`是指向`int`类型的指针。
- 指针存放某个对象的**地址**
- 获取对象的地址: `int i=42; int *p = &i;``&`是取地址符。
- 指针的值的四种状态:1.指向一个对象;2.指向紧邻对象的下一个位置;3.空指针;4.无效指针。
- 指针访问对象: `cout << *p;``*`是解引用符
- 指针访问对象: `cout << *p;``*`**解引用符**
- 空指针不指向任何对象。
- `void*`指针可以存放任意对象的地址
- 其他指针类型必须要与所指对象严格匹配
- `void*`指针可以存放**任意**对象的地址
- 其他指针类型必须要与所指对象**严格匹配**
- 两个指针相减的类型是`ptrdiff_t`

## const限定符
- 动机:希望定义一些不能被改变值的变量。
- const对象必须初始化,且不能被改变
- const对象**必须初始化**,且**不能被改变**
- const变量默认不能被其他文件访问,非要访问,必须在指定const前加extern。
- **reference to const**(对常量的引用):指向const对象的引用,如 `const int ival=1; const int &refVal = ival;`,可以读取但不能修改refVal。
- **pointer to const**(指向常量的指针):不能用于改变其所指对象的值, 如 `const double pi = 3.14; const double *cptr = &pi;`
Expand Down
10 changes: 5 additions & 5 deletions notes/ch3.md → notes/ch03.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
- 执行读操作:忽略掉开头的空白(包括空格、换行符和制表符),直到遇到下一处空白为止。
- `getline`:读取一整行,包括空白符。
- 字符串字面值和string是不同的类型。
- 遍历字符串:使用范围for(range for)语句: `for (auto c: str)`,或者 `for (auto &c: str)`使用引用直接改变字符串中的字符。
- 遍历字符串:使用**范围for**(range for)语句: `for (auto c: str)`,或者 `for (auto &c: str)`使用引用直接改变字符串中的字符。
- **ctype.h vs. cctype**:C++修改了c的标准库,名称为去掉“.h”,前面加“c”。

## vector
- vector是一个**容器**,也是一个类模板;
- `#include <vector>` 然后 `using std::vector;`
- 容器:包含其他对象。
- 类模板:本身不是类,但可以**实例化(instantiation)**出一个类。 `vector`是一个模板, `vector<int>`是一个类型。
- 通过将类型放在类模板名称后面的尖括号中来指定类型,如`vector<int> ivec`
- 类模板:本身不是类,但可以**实例化instantiation**出一个类。 `vector`是一个模板, `vector<int>`是一个类型。
- 通过将类型放在类模板名称后面的**尖括号**中来指定**类型**,如`vector<int> ivec`
- 列表初始化: `vector<string> v = {"a", "an", "the"}` (C++11)
- `v.push_back(e)` 在尾部增加元素。
- 范围for语句内不应该改变其遍历序列的大小。
Expand All @@ -45,7 +45,7 @@
- **容器**:可以包含其他对象;但所有的对象必须类型相同。
- **迭代器(iterator)**:每种标准容器都有自己的迭代器。C++倾向于用迭代器而不是下标遍历元素。
- **const_iterator**:只能读取容器内元素不能改变。
- 箭头运算符`it->mem`等价于 `(*it).mem`
- **箭头运算符**: 解引用+成员访问,`it->mem`等价于 `(*it).mem`
- **difference_type**:保证足够大以存储任何两个迭代器对象间的距离,可正可负。

## 数组
Expand Down Expand Up @@ -82,7 +82,7 @@

## 动态数组
- 使用 `new``delete`表达和c中`malloc``free`类似的功能,即在堆(自由存储区)中分配存储空间。
- 定义: `int *pia = new int[10];`,10可以被一个变量替代。
- 定义: `int *pia = new int[10];` 10可以被一个变量替代。
- 释放: `delete [] pia;`,注意不要忘记`[]`


Expand Down
6 changes: 6 additions & 0 deletions notes/ch04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 第四章 表达式

## 表达式基础
- **重载运算符**:当运算符作用在类类型的运算对象时,用户可以自行定义其含义。
- **左值和右值**:c中原意:左值**可以**在表达式左边,右值不能。c++:当一个对象被用作右值的时候,用的是对象的****(内容);被用做左值时,用的是对象的**身份**(在内存中的位置)。

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions notes/ch4.md

This file was deleted.

0 comments on commit fbf71b7

Please sign in to comment.