Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

compiler errors - no template named 'tuple' in C++

I am not allowed to initialise a tuple in C++. When I compile it comes up the following error while pointen at tuple: no template named 'tuple'. I am using Mac and have specified my tasks.json as shown in the bottom of the page.

Code

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

    tuple<int,int> f;

    return 0;
}

Error message:

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

1 error generated.

tasks.json (taken from https://code.visualstudio.com/docs/cpp/config-clang-mac where I have followed their guidelines):

{
"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."
    }
]

}

Compiler

% 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
question from:https://stackoverflow.com/questions/65920834/no-template-named-tuple-in-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on the comments, the problem was, that the task cppbuild was used instead of shell, and for that task, no c++ version was defined. Due to that default version for that compiler was used which does not support tuple.

Adding "-std=c++17", to the args of cppbuild solves that problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...