当前位置: 首页 > news >正文

Mac VsCode g++编译报错:不支持C++11语法解决

编译运行时报错:
[Running] cd “/Users/yiran/Documents/vs_projects/c++/” && g++ 1116.cpp -o 1116 && "/Users/yiran/Documents/vs_projects/c++/"1116
1116.cpp:28:22: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]

报错截图:
在这里插入图片描述
解决方案:
在.vscode/settings.json中配置如下,目的是在编译命令中添加编译选项-std=c++11

{"C_Cpp.errorSquiggles": "enabled","files.associations": {"vector": "cpp"},// 添加如下配置,对应文件路径替换成对应自己的路径"code-runner.executorMap": {"cpp": "cd '/Users/yiran/Documents/vs_projects/c++/' && g++ -std=c++11 $fullFileName -o $fileNameWithoutExt && ./$fileNameWithoutExt"}}

如果不生效,也可以在.vscode/tasks.json中添加如下配置,在编译命令中添加编译选项-std=c++11

{// See https://go.microsoft.com/fwlink/?LinkId=733558// for the documentation about the tasks.json format"version": "2.0.0","tasks": [{"type": "shell","label": "clang++ build active file","command": "/usr/bin/clang++","args": ["-std=c++17","-stdlib=libc++","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${workspaceFolder}"},"problemMatcher": ["$gcc"],"group": "build"},{"type": "cppbuild","label": "C/C++: clang 生成活动文件","command": "/usr/bin/clang","args": ["-std=c++17","-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "编译器: /usr/bin/clang"},{	"type": "cppbuild","label": "C/C++: g++ 生成活动文件","command": "/usr/bin/g++","args": ["-std=c++17","-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": "build","detail": "编译器: /usr/bin/g++"}]
}
http://www.lryc.cn/news/221921.html

相关文章:

  • react_12
  • Android Mvp案例解析
  • vue的双向绑定的原理,和angular的对比
  • 平衡树相关笔记
  • ASP.net C# 用Aspose.pdf实现pdf合并
  • C语言实现原码一位除
  • three.js点滴yan(整理后)
  • VMware安装CentOS最小化开发环境导引
  • 服务器端编程/数据库驱动程序/RESTful API:介绍
  • Qwt QwtThermo绘制温度计
  • U_boot介绍
  • Flink -- window(窗口)
  • 原语:串并转换器
  • 没网络也能安装.Net 3.5!如何脱机安装.NET Framework 3.5
  • JVM运行时数据区-虚拟机栈
  • Java中介者模式
  • 前端框架Vue学习 ——(五)前端工程化Vue-cli脚手架
  • App备案-iOS云管理式证书 Distribution Managed 公钥及证书SHA-1指纹的获取方法
  • Spring -Spring之依赖注入源码解析
  • Spire.Office for .NET 8.10.2 同步更新-Crk
  • MFC 基础篇(一)
  • Android技术-修改SO导出符号
  • flutter 打包apk
  • Halcon如何使用SaperaLT库连接dalsa相机
  • Vue 嵌套路由 多级路由规则
  • pandas教程:Introduction to pandas Data Structures pandas的数据结构
  • MinIO 分布式文件(对象)存储
  • HTML表单标签
  • 【黑马程序员】SpringCloud——Eureka
  • 目标跟踪(DeepSORT)