VS code c++11配置, 输出c++版本

本文介绍如何在VSCode中配置Mac环境以支持C++11标准,包括编辑器的任务设置、启动配置、编译器路径及标准设置等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Mac vscode默认配置中,c++的标准为c++98

输出c++版本

if (__cplusplus == 201703L) std::cout << "C++17\n";

else if (__cplusplus == 201402L) std::cout << "C++14\n";

else if (__cplusplus == 201103L) std::cout << "C++11\n";

else if (__cplusplus == 199711L) std::cout << "C++98\n";

else std::cout << "pre-standard C++\n";

(1) 配置task.json

Ctrl+Shift+P: 输入task,打开task.json

 改成以下内容

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "build",
			"command": "/usr/bin/clang++",
			"args": [
				"-std=c++11",
				"-stdlib=libc++",
				"-fdiagnostics-color=always",
				"${file}",
				"-o",
				"${fileDirname}/../build/${fileBasenameNoExtension}",
				"-g",
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault":true
			},
			"detail": "编译器: /usr/bin/clang++"
		}
	]
}

(2) 配置launch.json

或者在这里打开

 

改成以下内容

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "target": "./bin/executable",
            "cwd": "${workspaceRoot}",
            "valuesFormatting": "parseText"
        }
    ]
}

(3) 配置.vscode/c_cpp_properties.json

打开一个包含.cpp文件的文件夹(没有就自己创建)
“command+shift+p”打开命令行工具窗口,输入或者选择“Edit Configurations”命令。

此时会在当前工作空间目录生成.vscode配置目录,同时在配置目录会生成一个c_cpp_properties.json文件。 

改成以下内容

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

(4) 配置settings.json

 

打开settings.json

settings.json中。14行中加了 -std=c++11 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值