Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit 47fadc1

Browse files
author
Chen Xiaowei
committed
1. update 8-1
1 parent 740ed8b commit 47fadc1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

content/chapter8/chapter8-1-chinese.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ C++11之后,STL具有了很多用来测量和显示时间的新类型和函数
2121
using namespace std;
2222
```
2323

24-
2. `chrono::duration`经常用来表示所用时间的长度,其为秒的倍数或小数,所有STL的持续都由整型类型进行特化。本节中,将使用`double`进行特化。本节之后,我们更多的会关注已经存在于STL的时间单位:
24+
2. `chrono::duration`经常用来表示所用时间的长度,其为秒的倍数或小数,所有STL的程序都由整型类型进行特化。本节中,将使用`double`进行特化。本节之后,我们更多的会关注已经存在于STL的时间单位:
2525

2626
```c++
2727
using seconds = chrono::duration<double>;
@@ -125,10 +125,10 @@ C++11之后,STL具有了很多用来测量和显示时间的新类型和函数
125125
Sorry, your input does not match. You may try again.
126126
Please type the word "C++17" as fast as you can.
127127
> C++17
128-
Bravo. You did it in:
129-
1.48 seconds.
130-
1480.10 milliseconds.
131-
1480099.00 microseconds.
128+
Bravo. You did it in:
129+
2.82 seconds.
130+
2817.95 milliseconds.
131+
2817948.40 microseconds.
132132
```
133133

134134
## How it works...
@@ -180,4 +180,4 @@ using microseconds = chrono::duration<double, ratio<1, 1000000>>;
180180

181181
## There's more...
182182

183-
其他教程和书籍中,你可以会看到使用`duration_cast`的方式对时间进行转换。当我们具有一个时间间隔类`chrono::milliseconds`和要转换成的类型`chrono::hours`时,就需要转换为`duration_cast<chrono::hours>(milliseconds_value)`,因为这些时间单位都是整型。从一个细粒度的时间单位,转换成一个粗粒度的时间单位,将会带来时间精度的损失,这也是为什么我们使用`duration_cast`的原因。对于基于`double``float`的时间间隔类型不需要进行强制转换。
183+
其他教程和书籍中,你可以会看到使用`duration_cast`的方式对时间进行转换。当我们具有一个时间间隔类`chrono::milliseconds`和要转换成的类型`chrono::hours`时,就需要转换为`duration_cast<chrono::hours>(milliseconds_value)`,因为这些时间单位都是整型。从一个细粒度的时间单位,转换成一个粗粒度的时间单位,将会带来时间精度的损失,这也是为什么我们使用`duration_cast`的原因。基于`double``float`的时间间隔类型不需要进行强制转换。

0 commit comments

Comments
 (0)