繁体   English   中英

如何在VSCode C++扩展中启用C++17标准

[英]How to enable C++17 standard in VSCode C++ Extension

我想在 vs 代码中将 c++11 切换为 c++17。 我尝试按照说明进行操作,但没有用。

任务.json

"version": "2.0.0",
"tasks": [
    
    {
        "type": "cppbuild",
        "label": "C/C++: g++ build active file",
        "command": "/usr/bin/g++",
        "args": [
            "-g",
            "-Wall",
            "-std=c++17",
            "${fileDirname}/*.cpp",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/g++"
    }
]

c_cpp_properties.json

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

启动.json

// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "g++ - Build and debug active file",
        "type": "lldb",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [
            
        ],
        "cwd": "${fileDirname}",
        "preLaunchTask": "C/C++: g++ build active file"
    }
]

设置.json

"C_Cpp.errorSquiggles": "Enabled",
"C_Cpp.default.cppStandard": "c++17",
"files.associations": {
    "*html": "html",
    "iostream": "cpp",
    "iosfwd": "cpp",
    "ostream": "cpp",
    "istream": "cpp",
    "fstream": "cpp",
    "new": "cpp",
    "__bit_reference": "cpp",
    "__config": "cpp",
    "__debug": "cpp",
    "__errc": "cpp",
    "__functional_base": "cpp",
    "__hash_table": "cpp",
    "__locale": "cpp",
    "__mutex_base": "cpp",
    "__node_handle": "cpp",
    "__nullptr": "cpp",
    "__split_buffer": "cpp",
    "__string": "cpp",
    "__threading_support": "cpp",
    "__tree": "cpp",
    "__tuple": "cpp",
    "algorithm": "cpp",
    "array": "cpp",
    "atomic": "cpp",
    "bit": "cpp",
    "bitset": "cpp",
    "cctype": "cpp",
    "chrono": "cpp",
    "cmath": "cpp",
    "complex": "cpp",
    "cstdarg": "cpp",
    "cstddef": "cpp",
    "cstdint": "cpp",
    "cstdio": "cpp",
    "cstdlib": "cpp",
    "cstring": "cpp",
    "ctime": "cpp",
    "cwchar": "cpp",
    "cwctype": "cpp",
    "deque": "cpp",
    "exception": "cpp",
    "functional": "cpp",
    "initializer_list": "cpp",
    "iomanip": "cpp",
    "ios": "cpp",
    "iterator": "cpp",
    "limits": "cpp",
    "list": "cpp",
    "locale": "cpp",
    "map": "cpp",
    "memory": "cpp",
    "mutex": "cpp",
    "numeric": "cpp",
    "optional": "cpp",
    "queue": "cpp",
    "ratio": "cpp",
    "set": "cpp",
    "sstream": "cpp",
    "stack": "cpp",
    "stdexcept": "cpp",
    "streambuf": "cpp",
    "string": "cpp",
    "string_view": "cpp",
    "system_error": "cpp",
    "tuple": "cpp",
    "type_traits": "cpp",
    "typeinfo": "cpp",
    "unordered_map": "cpp",
    "utility": "cpp",
    "vector": "cpp",
    "thread": "cpp"
}

在 C/C++ 配置 (UI) 中也更改为 c++17。

由于这个问题,我在编译我的作品时遇到了麻烦。 生成此警告:

执行任务:C/C++: g++ build active file < Starting build... /usr/bin/g++ -g -Wall -std=c++17 /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/*.cpp -o /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/w2_p1 /Users/aziznosirov/Documents/cpp_udemy/btp305_w2_p1/w2_p1.cpp:43:14: 警告:ISO C++11 不允许从字符串文字转换为 'char *' [-Wwritable -strings] t.addEvent(" 0-arg Constructor");

你可以看到,虽然在构建时编译器上显示为 c++17,但它仍然会生成一个警告,提及 c++11。

任何帮助,将不胜感激。 谢谢。

查看Build Task ,我们可以看到代码实际上是使用-std=c++17标志显式编译的。

我怀疑正在使用的编译器不是最近的编译器, GCC -7对 C++ 17 种功能提供了实验性支持,可以通过使用-std=c++1z标志来使用这些功能。

从 GCC 8 开始,编译器已完全支持 C++17。

我建议更新 GCC package。

我解决了这个问题。 我只需要添加一个常量。 我的 c++17 实际上在工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM