C++之旅(第3版)

C++之旅(第3版)

《C++之旅(第3版)》是2023年10月電子工業出版社出版圖書,作者是【美】Bjarne Stroustrup。

基本介紹

  • 中文名:C++之旅(第3版)
  • 作者:【美】Bjarne Stroustrup
  • 譯者:Pansz
  • 出版時間:2023年10月
  • 出版社:電子工業出版社
  • 頁數:320 頁
  • ISBN:9787121461248
  • 定價:109 元
  • 開本:16 開
圖書目錄,作者簡介,

圖書目錄

第 1 章基礎............................................................................................................................1
1.1 引言...............................................................................................................................1
1.2 程式...............................................................................................................................2
1.2.1 Hello,World!.................................................................................................................2
1.3 函式...............................................................................................................................4
1.4 類型、變數與運算........................................................................................................6
1.4.1 算術運算.......................................................................................................................7
1.4.2 初始化...........................................................................................................................9
1.5 作用域和生命周期......................................................................................................10
1.6 常量.............................................................................................................................11
1.7 指針、數組和引用......................................................................................................13
1.7.1 空指針..........................................................................................................................15
1.8 檢驗.............................................................................................................................16
1.9 映射到硬體 .................................................................................................................19
1.9.1 賦值..............................................................................................................................19
1.9.2 初始化..........................................................................................................................20
1.10 建議...........................................................................................................................21
第 2 章用戶自定義類型........................................................................................................23
2.1 引言.............................................................................................................................23
2.2 結構 .............................................................................................................................24
2.3 類 .................................................................................................................................25
2.4 枚舉 .............................................................................................................................27
2.5 聯合 .............................................................................................................................29
2.6 建議 .............................................................................................................................31
第 3 章模組化......................................................................................................................32
3.1 引言.............................................................................................................................32
3.2 分離編譯.....................................................................................................................33
3.2.1 頭檔案..........................................................................................................................34
3.2.2 模組..............................................................................................................................36
3.3 命名空間.....................................................................................................................39
3.4 函式參數與返回值......................................................................................................41
3.4.1 參數傳遞......................................................................................................................42
3.4.2 返回值..........................................................................................................................43
3.4.3 返回類型推導..............................................................................................................45
3.4.4 返回類型後置..............................................................................................................45
3.4.5 結構化綁定..................................................................................................................46
3.5 建議.............................................................................................................................47
第 4 章錯誤處理...................................................................................................................48
4.1 引言.............................................................................................................................48
4.2 異常.............................................................................................................................49
4.3 約束條件.....................................................................................................................50
4.4 錯誤處理的其他替代方式..........................................................................................52
4.5 斷言.............................................................................................................................54
4.6 建議.............................................................................................................................57
第 5 章類..............................................................................................................................58
5.1 引言.............................................................................................................................58
5.1.1 類的概述 ......................................................................................................................59
5.2 具體類型.....................................................................................................................59
5.2.1 一種算術類型 ..............................................................................................................60
5.2.2 容器..............................................................................................................................62
5.2.3 容器的初始化 ..............................................................................................................64
5.3 抽象類型.....................................................................................................................66
5.4 虛函式.........................................................................................................................69
5.5 類層次結構.................................................................................................................70
5.5.1 類層次結構的益處......................................................................................................72
5.5.2 類層次結構導航..........................................................................................................74
5.5.3 避免資源泄露..............................................................................................................75
5.6 建議.............................................................................................................................76
第 6 章基本操作...................................................................................................................78
6.1 引言.............................................................................................................................78
6.1.1 基本操作......................................................................................................................79
6.1.2 轉換..............................................................................................................................81
6.1.3 成員初始值設定項......................................................................................................81
6.2 拷貝和移動.................................................................................................................82
6.2.1 拷貝容器......................................................................................................................82
6.2.2 移動容器......................................................................................................................84
6.3 資源管理.....................................................................................................................87
6.4 操作符重載.................................................................................................................88
6.5 常規操作.....................................................................................................................89
6.5.1 比較(關係操作符)..................................................................................................90
6.5.2 容器操作......................................................................................................................92
6.5.3 疊代器及智慧型指針......................................................................................................92
6.5.4 輸入與輸出操作..........................................................................................................93
6.6 用戶自定義字面量......................................................................................................93
6.7 建議.............................................................................................................................94
第 7 章模板..........................................................................................................................96
7.1 引言.............................................................................................................................96
7.2 參數化類型.................................................................................................................97
7.2.1 受限模板參數..............................................................................................................99
7.2.2 模板值參數................................................................................................................100
7.2.3 模板參數推導............................................................................................................100
7.3 參數化操作...............................................................................................................102
7.3.1 模板函式....................................................................................................................103
7.3.2 函式對象....................................................................................................................103
7.3.3 匿名函式表達式........................................................................................................105
7.4 模板機制...................................................................................................................109
7.4.1 模板變數....................................................................................................................109
7.4.2 別名............................................................................................................................110
7.4.3 編譯時if.....................................................................................................................111
7.5 建議...........................................................................................................................113
第 8 章概念和泛型編程......................................................................................................114
8.1 引言...........................................................................................................................114
8.2 概念...........................................................................................................................115
8.2.1 概念的運用................................................................................................................116
8.2.2 基於概念的重載 ........................................................................................................117
8.2.3 有效代碼....................................................................................................................118
8.2.4 定義概念....................................................................................................................119
8.2.5 概念與 auto................................................................................................................122
8.2.6 類型與概念 ................................................................................................................124
8.3 泛型編程...................................................................................................................124
8.3.1 概念的使用 ................................................................................................................124
8.3.2 使用模板實現抽象....................................................................................................125
8.4 可變參數模板...........................................................................................................127
8.4.1 摺疊表達式................................................................................................................128
8.5 模板編譯模型...........................................................................................................130
8.6 建議...........................................................................................................................131
第 9 章標準庫....................................................................................................................132
9.1 引言...........................................................................................................................132
9.2 標準庫組件...............................................................................................................133
9.3 標準庫的組織...........................................................................................................134
9.3.1 命名空間....................................................................................................................134
9.3.2 ranges 命名空間.........................................................................................................135
9.3.3 模組............................................................................................................................136
9.3.4 頭檔案........................................................................................................................136
9.4 建議...........................................................................................................................138
第 10 章字元串和正則表達式.............................................................................................139
10.1 引言.........................................................................................................................139
10.2 字元串 .....................................................................................................................139
10.2.1 string 的實現............................................................................................................142
10.3 字元串視圖 .............................................................................................................142
10.4 正則表達式.............................................................................................................144
10.4.1 搜尋..........................................................................................................................145
10.4.2 正則表達式的符號表示...........................................................................................146
10.4.3 疊代器......................................................................................................................151
10.5 建議.........................................................................................................................151
第 11 章輸入和輸出...........................................................................................................153
11.1 引言.........................................................................................................................153
11.2 輸出 .........................................................................................................................154
11.3 輸入.........................................................................................................................156
11.4 I/O 狀態 ...................................................................................................................157
11.5 用戶自定義類型的 I/O...........................................................................................158
11.6 輸出格式化 .............................................................................................................159
11.6.1 流式格式化..............................................................................................................160
11.7 流.............................................................................................................................164
11.7.1 標準流......................................................................................................................164
11.7.2 檔案流......................................................................................................................165
11.7.3 字元串流 ..................................................................................................................165
11.7.4 記憶體流......................................................................................................................166
11.7.5 同步流......................................................................................................................167
11.8 C 風格的I/O............................................................................................................168
11.9 檔案系統.................................................................................................................168
11.9.1 路徑..........................................................................................................................168
11.9.2 檔案和目錄..............................................................................................................171
11.10 建議.......................................................................................................................172
第 12 章容器......................................................................................................................174
12.1 引言.........................................................................................................................174
12.2 vector.......................................................................................................................175
12.2.1 元素..........................................................................................................................178
12.2.2 範圍檢查..................................................................................................................178
12.3 list............................................................................................................................180
12.4forward_list..............................................................................................................181
12.5 map..........................................................................................................................182
12.6 unordered_map........................................................................................................183
12.7 分配器.....................................................................................................................184
12.8 容器概述 .................................................................................................................186
12.9 建議.........................................................................................................................188
第 13 章算法......................................................................................................................190
13.1 引言.........................................................................................................................190
13.2 使用疊代器 .............................................................................................................192
13.3 疊代器類型.............................................................................................................195
13.3.1 流疊代器 ..................................................................................................................196
13.4 使用謂詞.................................................................................................................199
13.5 標準庫算法概覽 .....................................................................................................199
13.6 並行算法.................................................................................................................201
13.7 建議.........................................................................................................................202
第 14 章範圍......................................................................................................................203
14.1 引言.........................................................................................................................203
14.2 視圖.........................................................................................................................204
14.3 生成器.....................................................................................................................206
14.4 管道.........................................................................................................................207
14.5 概念概述.................................................................................................................208
14.5.1 類型概念..................................................................................................................209
14.5.2 疊代器概念..............................................................................................................211
14.5.3 範圍概念..................................................................................................................212
14.6 建議.........................................................................................................................213
第 15 章指針和容器...........................................................................................................214
15.1 引言.........................................................................................................................214
15.2 指針類型.................................................................................................................215
15.2.1 unique_ptr 及shared_ptr...........................................................................................216
15.2.2span...........................................................................................................................219
15.3 容器.........................................................................................................................221
15.3.1array..........................................................................................................................222
15.3.2 bitset.........................................................................................................................224
15.3.3pair............................................................................................................................225
15.3.4 tuple..........................................................................................................................227
15.4 可變類型容器 .........................................................................................................229
15.4.1variant.......................................................................................................................229
15.4.2 optional.....................................................................................................................231
15.4.3 any............................................................................................................................232
15.5 建議 .........................................................................................................................233
第 16 章實用工具...............................................................................................................234
16.1 引言.........................................................................................................................234
16.2 時間.........................................................................................................................235
16.2.1 時鐘..........................................................................................................................235
16.2.2 日曆..........................................................................................................................236
16.2.3 時區..........................................................................................................................237
16.3 函式適配.................................................................................................................237
16.3.1 匿名函式作為適配器..............................................................................................238
16.4 類型函式.................................................................................................................239
16.4.1 類型謂詞..................................................................................................................240
16.4.2 條件屬性..................................................................................................................242
16.4.3 類型生成器..............................................................................................................242
16.4.4 關聯類型..................................................................................................................243
16.7 位操作.....................................................................................................................246
16.8 退出程式.................................................................................................................247
16.9 建議.........................................................................................................................248
第 17 章數值計算...............................................................................................................249
17.1 引言.........................................................................................................................249
17.2 數學函式.................................................................................................................250
17.3 數值計算算法.........................................................................................................251
17.3.1 並行數值算法..........................................................................................................251
17.4 複數.........................................................................................................................252
17.5 隨機數.....................................................................................................................253
17.6 向量算術.................................................................................................................255
17.7 數值界限.................................................................................................................256
17.8 類型別名.................................................................................................................256
17.9 數學常數.................................................................................................................256
17.10 建議.......................................................................................................................257
第 18 章並發......................................................................................................................259
18.1 引言.........................................................................................................................259
18.2 任務和 thread..........................................................................................................260
18.2.1 傳遞參數..................................................................................................................262
18.2.2 返回結果..................................................................................................................262
18.3 共享數據.................................................................................................................263
18.3.1 mutex 和鎖...............................................................................................................263
18.3.2 原子量......................................................................................................................265
18.4 等待事件.................................................................................................................266
18.5 任務間通信.............................................................................................................268
18.5.1 future 和 promise......................................................................................................268
18.5.2packaged_task...........................................................................................................269
18.6 協程.........................................................................................................................273
18.6.1 協作式多任務..........................................................................................................274
18.7 建議.........................................................................................................................277
第 19 章歷史和兼容性........................................................................................................279
19.1 歷史.........................................................................................................................279
19.1.1 大事年表..................................................................................................................280
19.1.2 早期的 C++..............................................................................................................281
19.1.3 ISO C++標準............................................................................................................284
19.1.4 標準與編程風格......................................................................................................286
19.1.5 C++的使用...............................................................................................................287
19.1.6 C++模型...................................................................................................................287
19.2 C++特性演化..........................................................................................................288
19.2.1 C++11 語言特性......................................................................................................288
19.2.2 C++14 語言特性......................................................................................................289
19.2.3 C++17 語言特性......................................................................................................290
19.2.4 C++20 語言特性......................................................................................................290
19.2.5 C++11 標準庫組件..................................................................................................291
19.2.6 C++14 標準庫組件..................................................................................................292
19.2.7 C++17 標準庫組件..................................................................................................292
19.2.8 C++20 標準庫組件 ..................................................................................................292
19.2.9 移除或棄用的特性..................................................................................................293
19.3 C/C++兼容性 ..........................................................................................................294
19.3.1 C 與 C++是兄弟.......................................................................................................294
19.3.2 兼容性問題 ..............................................................................................................295
19.4 參考文獻.................................................................................................................298
19.5 建議 .........................................................................................................................301
附錄 A std 模組...................................................................................................................303

作者簡介

Stroustrup 是 C++ 的設計者和原始實現者,也是本書及《C++程式設計原理與實踐》(第2版)和《C++程式設計語言》(第4版)等領域名著的作者。是哥倫比亞大學教授,之前曾在 AT&T 貝爾實驗室、德克薩斯A&M 大學和摩根史坦利工作。他曾獲得無數榮譽,包括因開發和改進 C++ 程式語言所獲的美國國家工程院查爾斯·斯塔克·德雷珀獎。Stroustrup 博士是美國國家工程院院士,也是IEEE、ACM、CHM 和劍橋邱吉爾學院的院士。
譯者簡介
譯者pansz是一個經驗豐富的軟體工程師,從國小開始學習編程,中學時期已成為高級程式設計師。
check!

熱門詞條

聯絡我們