## 編譯錯誤的類型 1. 忘記加上 using namespace std;(或是忘記 include 等,模板的部分打錯) ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> int main() { int x, y; cin >> x >> y; cout << x + y << '\n'; } ``` 2. 打錯任意關鍵字 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<oistream> use namaspace std; int main() { int x, y; cin >> x >> y; cout << x + y << '\n'; } ``` 3. 忘記宣告變數 ```cpp= // 讀入 x 並輸出 x #include<iostream> using namespace std; int main() { cin >> x; cout << x << '\n'; } ``` 4. 忘記分號 ```cpp= // 讀入 x 並輸出 x #include<iostream> using namespace std; int main() { int x cin >> x cout << x << '\n' } ``` 5. 全形空白、符號 ```cpp= // 讀入 x 並輸出 x #include<iostream> using namespace std; int main() {     int x;     cin >> x;     cout << x << '\n'; } ``` 6. cin,cout 所使用的運算子(>>,<<) 弄反 ```cpp= // 讀入 x 並輸出 x #include<iostream> using namespace std; int main() { int x; cin << x; cout >> x >> '\n'; } ``` 7. 指派運算子順序左右搞反 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> using namespace std; int main() { int x, y, answer; cin >> x >> y; x + y = answer; cout << answer << '\n'; } ``` 8. 同一個 token 的兩個字元間出現多餘的空白 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> using namespace std; int main() { int x, y; cin > > x >> y; cout << x + y << '\n'; } ``` 9. include 前面忘記加上井字號 ```cpp= // 讀入 x 和 y 並輸出 x + y include<iostream> using namespace std; int main() { int x, y; cin >> x >> y; cout << x + y << '\n'; } ``` 10. 少一個大括號 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> using namespace std; int main() { int x, y; cin >> x >> y; cout << x + y << '\n'; ``` 11. 大小寫混用 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> using namespace std; int main() { int x, y; cin >> X >> Y; cout << X + Y << '\n'; } ``` 12. 誤以為 C++ 運算式的括號也有小括號中括號大括號之分。 ```cpp= // 讀入 x, y 和 z 並輸出 [(x + y) * z + x] * y #include<iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << [(x + y) * z + x] * y << endl; } ``` ## 可從 Warning 看出的錯誤 1. 輸入輸出兩個以上的東西用逗號分隔 ```cpp= // 讀入 x 和 y 並輸出 x + y #include<iostream> using namespace std; int main() { int x, y; cin >> x, y; cout << x + y << '\n'; } ``` ## 不熟悉語法類型 1. 誤把 Python 比較運算子的規則用在 C++ 上 ```cpp= #include<iostream> using namespace std; int main() { // 判斷 a 和 b 和 c 三個數是否相等 int a, b, c; cin >> a >> b >> c; if(a == b == c) { // 正確為 a== b && b == c cout << "same" << endl; } else { cout << "different" << endl; } } ```