[Visual Studio Code] Sửa lỗi “Error: Range-based ‘for’ loops are not allowed in C++98 mode”

[Visual Studio Code] Sửa lỗi “Error: Range-based ‘for’ loops are not allowed in C++98 mode”
a20ff224e8b36dac9fd0b2d1d0fe63e7622c1622 - quochung.cyou PTIT
[Visual Studio Code] Sửa lỗi "Error: Range-based 'for' loops are not allowed in C++98 mode" 13

Lỗi được báo khi bạn dùng auto trong for, nhưng VS Code báo trình biên dịch C++ của bạn đang quá cũ

Bạn hãy thử cập nhật Mingw theo hướng dẫn sau: http://213.35.113.17:9002/cach-cai-dat-c-mingw-cho-vs-code-c-20/

Nếu bạn dùng Extension Code Runner để chạy code

  1. Vào Extensions (Ctrl Shift X), tìm Code Runner
  2. Ấn vào hình bánh răng => Extension Setting
  3. Tìm đến Code Runner – Executor map – > Edit in setting.json
  4. Ở mục cpp sẽ có dạng như này: cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt
  5. Bạn sửa thành cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt (Thêm std=c++11 để ép trình compiler chạy code với c++11, bạn có thể sửa thành c++14 hoặc c++17 – có thể mingw của bạn không có 14/17, nếu lỗi hãy thử 11)

Nếu bạn dùng Extension CPH (Competitive Programming Helper) để chạy code

  1. Vào Extensions (Ctrl Shift X), tìm Competitive Programming Helper
  2. Ấn vào hình bánh răng => Extension Setting
  3. Tìm đến Code Runner – Executor map – > Edit in setting.json
  4. Ở mục “CPH > Language > Cpp: Args”
  5. Bạn cho vào std=c++11 (Thêm std=c++11 để ép trình compiler chạy code với c++11, bạn có thể sửa thành c++14 hoặc c++17 – có thể mingw của bạn không có 14/17, nếu lỗi hãy thử 11)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply