OSDN Git Service

Update io.md
authororzcyand1317 <36555123+orzcyand1317@users.noreply.github.com>
Tue, 5 Mar 2019 06:01:35 +0000 (14:01 +0800)
committerGitHub <noreply@github.com>
Tue, 5 Mar 2019 06:01:35 +0000 (14:01 +0800)
docs/misc/io.md

index 77c8c20..19f6bad 100644 (file)
@@ -42,6 +42,7 @@ std::cin.tie(0);
 
 C 和 C++ 语言分别在 ctype.h 和 cctype 头文件中,提供了函数 `isdigit` , 这个函数会检查传入的参数是否为十进制数字字符,是则返回 **true** ,否则返回 **false** 。对应的,在下面的代码中,可以使用 `isdigit(ch)` 代替 `ch >= '0' && ch <= '9'` ,而可以使用 `!isdigit(ch)` 代替 `ch <'0' || ch> '9'` 
 
+
 ### 代码实现
 
 ```cpp
@@ -56,6 +57,8 @@ int read() {
     x = x * 10 + (ch - '0');  // 将新读入的数字’加’在 x 的后面
     // x 是 int 类型,char 类型的 ch 和 ’0’ 会被自动转为其对应的
     // ASCII 码,相当于将 ch 转化为对应数字
+    // 此处也可以使用 (x<<3)+(x<<1) 的写法来代替 x*10
+    // 但是这样在大部分情况下会导致代码效率变低,故不建议采用此类写法
     ch = getchar();  // 继续读入
   }
   return x * w;  // 数字 * 正负号 = 实际数值