OSDN Git Service

add some mistakes
authorShuhao Zhang <594422141@qq.com>
Mon, 25 Feb 2019 16:51:50 +0000 (00:51 +0800)
committerGitHub <noreply@github.com>
Mon, 25 Feb 2019 16:51:50 +0000 (00:51 +0800)
docs/intro/common-mistakes.md

index 6ac86a4..93848ea 100644 (file)
 
 14. 存图下标从 0 开始输入节点未 -1.
 
-15. 没有考虑数组下标出现负数的情况
-
-16. scanf 读入的时候没加 & 取地址符
+15. 赋值运算符和`==`不分。
+    - 示例:
+      ```cpp
+      if(n=1)puts("Yes");
+      else puts("No");
+      ```
+      无论 $ n $ 的值之前为多少,输出肯定是`Yes`。
+      
+
+16. 没有考虑数组下标出现负数的情况
+
+17. scanf 读入的时候没加 & 取地址符
+
+18. 在执行`ios::sync_with_stdio(false);`后混用两种IO,导致输出错乱。
+    - 可以参考这个例子。
+      ```cpp
+      //这个例子将说明,关闭与stdio的同步后,混用两种IO的后果
+      //建议单步运行来观察效果
+      #include <iostream>
+      #include <cstdio>
+      using namespace std;
+      int main()
+      {
+       ios::sync_with_stdio(false);
+       //关闭IO后,cin/cout将使用独立缓冲区,而不是将输出同步至scanf/printf的缓冲区,从而减少IO耗时
+       cout<<"a\n";
+       //cout下,使用'\n'换行时,内容会被缓冲而不会被立刻输出,应该使用endl来换行并立刻刷新缓冲区
+       printf("b\n");
+       //printf的'\n'会刷新printf的缓冲区,导致输出错位
+       cout<<"c\n";
+       return 0;//程序结束时,cout的缓冲区才会被输出
+      }
+      ```