25k words 23 mins.

# Chapter 9 Sequential Containers # Overview of the Sequential Containers # 顺序容器概述 顺序容器(sequential container):为程序员提供了控制元素存储和访问顺序的能力。这种顺序不依赖于元素的值,而是与元素加入容器时的位置相对应。 # 顺序容器类型 容器类型 介绍 vector 可变大小数组。支持快速随机访问。在尾部之外的位置插入或删除元素可能很慢。 deque 双端队列。支持快速随机访问。在头尾位置插入 / 删除速度很快。 list 双向链表。只支持双向顺序访问。在 list...
8.1k words 7 mins.

# Chapter 8 The IO Library # 前面章节已经在用的 IO 库设施 istream:输入流类型,提供输入操作。 ostream:输出流类型,提供输出操作 cin:一个 istream 对象,从标准输入读取数据。 cout:一个 ostream 对象,向标准输出写入数据。 cerr:一个 ostream 对象,向标准错误写入消息。 >> 运算符:用来从一个 istream 对象中读取输入数据。 << 运算符:用来向一个 ostream 对象中写入输出数据。 getline 函数:从一个给定的 istream...
25k words 23 mins.

# Chapter 7 Classes # Defining Abstract Data Types # 定义抽象数据类型 类背后的基本思想:数据抽象(data abstraction)和封装(encapsulation)。 数据抽象是一种依赖于接口(interface)和实现(implementation)分离的编程技术。 # 类成员 (Member) 必须在类的内部声明,不能在其他地方增加成员。 成员可以是数据,函数,类型别名。 # 类的成员函数 成员函数的声明必须在类的内部。 成员函数的定义既可以在类的内部也可以在外部。 使用点运算符 . 调用成员函数。 必须对任何...
18k words 16 mins.

# Chapter 6 Functions # Function Basics # 函数基础 函数定义:包括返回类型、函数名字和 0 个或者多个形参(parameter)组成的列表和函数体。 调用运算符:调用运算符的形式是一对圆括号 () ,作用于一个表达式,该表达式是函数或者指向函数的指针。 圆括号内是用逗号隔开的实参(argument)列表。 函数调用过程: 1. 主调函数(calling function)的执行被中断。 2. 被调函数(called function)开始执行。 形参和实参:形参和实参的个数和类型必须匹配上。 返回类型: void...
13k words 12 mins.

# Chapter 5 Statements # Simple Statements # 简单语句 表达式语句:一个表达式末尾加上分号,就变成了表达式语句。 空语句:只有一个单独的分号。 复合语句(块):用花括号 {} 包裹起来的语句和声明的序列。一个块就是一个作用域。 # Exercise 5.1 什么是空语句?什么时候会用到空语句? 解: 只含义一个单独的分号的语句是空语句。如: ; 。 如果在程序的某个地方,语法上需要一条语句但是逻辑上不需要,此时应该使用空语句。 while (cin >> s &&...
11k words 10 mins.

# Chapter 4 Expressions # Fundamentals # 表达式基础 运算对象转换:小整数类型会被提升为较大的整数类型 重载运算符:当运算符作用在类类型的运算对象时,用户可以自行定义其含义。 左值和右值: C 中原意:左值可以在表达式左边,右值不能。 C++ :当一个对象被用作右值的时候,用的是对象的值(内容); 被用做左值时,用的是对象的身份(在内存中的位置)。 求值顺序: int i = f1() + f2() 先计算 f1() + f2() , 再计算 int i = f1() + f2() 。但是 f1 和 f2 的计算先后不确定 但是,如果...
22k words 20 mins.

# Chapter 3 Strings, Vectors, and Arrays # Namespace using Declarations # using 声明 使用某个命名空间:例如 using std::cin 表示使用命名空间 std 中的名字 cin 。 头文件中不应该包含 using 声明。这样使用了该头文件的源码也会使用这个声明,会带来风险。 # Exercise 3.1 使用恰当的 using 声明重做 1.4.1 节和 2.6.2 节的练习。 解: 1.4.1 #include <iostream>using std::cin;using...
15k words 14 mins.

# Chapter 2 Variables and Basic Types # Primitive Built-in Types C++ defines a set of primitive types that include the arithmetic types and a special type named void. The arithmetic types represent characters, integers, boolean values, and floating-point numbers. The void type has no associated...
16k words 15 mins.

# Chapter 1 Getting Started # Writing a Simple C++ Program Section Having written the program, we need to compile it. How you compile a program depends on your operating system and compiler. For details on how your particular compiler works, check the reference manual or ask a knowledgeable...
51k words 46 mins.

# Chapter 25 Interoperating with WinRT Components Windows 8 comes with a new class library allowing applications to access operating system functionality. The formal name for this class library is the Windows Runtime (WinRT) and its components are accessible using the WinRT type system. WinRT has...