# c++20 tutorial **Repository Path**: liusabc/c20-tutorialc ## Basic Information - **Project Name**: c++20 tutorial - **Description**: c++20 高级编程 课本源代码。 非module版本 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-08-01 - **Last Updated**: 2023-08-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ReadMe 说明: 1. 本repo 来自C++20高级编程 源码。 ~~2. 本repo 编译使用gcc(g++) 12.x 版本。 此版本暂不支持c++20 引入的 std::format 库。 所以代码将进行替换使用printf进行格式化或字符串输出。 (可使用第三方fmt库进行替换,考虑这个repo仅做c++语言学习使用,为了code的简介所以暂不考虑引用第三方fmt库)~~ 3. 使用gcc13 以上版本支持 库 4. 书中大量使用module,考虑到编译器module编译存在bug不是很清楚。 将对源码中的repo module进行改写为熟悉的 `xxx.h` 和 `xxx.cpp` 文件格式。 ## 重点章节 - chapter2 介绍C-Style的字符串和c++11之后引入的 string 及c++17后引入的string_view。 - chapter7 c++指针概念 - chapter8 介绍class - **chapter9** 进一步检查class及相关高级内容 , `copy constructor`、`copy assginment constructor`、`move constructor` - chapter12 重点概念 泛型编程。创建通用模板 - chapter13 stream 流的概念 - chapter15 运算符重载 - **chapter16** StandardLib 介绍,包括C++20 引入的``库,`cpm_equal()` 。 `Container and Algorithm` 重点内容 - **chapter17** iterator 介绍, c++20 新增的 range 和view 的使用 - **chapter18** stl容器详细介绍,原理及相关使用方法。 **重点章节** ### 编译存在问题 1. g++ 不识别书中定义的`.cppm` 模块文件, 需要将模块文件后缀更改为`.cxx`; 2. g++ 在编译时需要指定 编译的c++版本`-std=c++20`,和使用模块编译 `-fmodules-ts` 3. . 标准库无法直接导入需要手动将其编译生module 在进行编译 (c01_code/01_HelloWorld/helloworld.cpp) 中编译语句 ```s # 将iostream string 编译成单元进行输出 g++ -std=c++20 -fmodules-ts -xc++-system-header iostream g++ -std=c++20 -fmodules-ts -xc++-system-header string # 在编译生成对应文件。 g++ -std=gnu++20 -fmodules-ts .\helloworld.cpp -o hello.exe ``` 1. 编译多线程模块时,g++ 需要使用`posixs` 版本, win32版本暂不支持c++11之后的thread