簡體   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