C++ 中没有名为 'tuple' 的模板

no template named 'tuple' in C++

不允许我在 C++ 中初始化元组。当我编译它时出现以下错误,同时指向 tuple: no template named 'tuple'。我正在使用 Mac 并指定了我的 tasks.json,如页面底部所示。

代码

#include <tuple>
#include <iostream>
using namespace std;
int main() {

    tuple<int,int> f;

    return 0;
}

错误信息:

error: no template named 'tuple'
tuple<int,int> f;
^

产生了 1 个错误。

tasks.json(摘自 https://code.visualstudio.com/docs/cpp/config-clang-mac 我遵循了他们的指导方针):

{
"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++ build active file",
        "command": "/usr/bin/clang++",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
]

}

编译器

% clang --version
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

根据评论,问题是使用了任务 cppbuild 而不是 shell,并且对于该任务,没有定义 c++ 版本。由于使用了不支持 tuple.

的编译器的默认版本

"-std=c++17", 添加到 cppbuildargs 可以解决该问题。