为什么 g++ 不能编译元组?

Gol*_*ame 1 c++

#include <iostream>
#include <tuple>
#include <string>
using namespace std;

int main(){
  tuple<string, string, string> x;
  x = make_tuple("hi", "a", "b");
  cout << get<0>(x) << endl << endl;

}
Run Code Online (Sandbox Code Playgroud)

我的程序遇到了困难,所以我写了一个更简单的程序,即使这样也行不通。我不明白为什么在多次查看文档后会出现问题。它在 XCode 上也能很好地编译,但由于某种原因在 g++ 上出现故障。

这是完整的错误消息:

test.cpp:6:3: 错误:使用未声明的标识符“元组”

元组 x;

^

test.cpp:6:9: 错误:意外的类型名称“字符串”:预期的表达式

元组 x;

    ^
Run Code Online (Sandbox Code Playgroud)

test.cpp:7:3: 错误:使用未声明的标识符“x”

x = make_tuple("hi", "a", "b");

^

test.cpp:7:7: 错误:使用未声明的标识符“make_tuple”

x = make_tuple("hi", "a", "b");

  ^
Run Code Online (Sandbox Code Playgroud)

test.cpp:8:11: 错误:无法解析对重载函数的引用;你的意思是打电话吗?cout << get<0>x << endl << endl;

我使用的命令是 g++ test.cpp

jba*_*bab 6

试试#include <string>

可能(取决于您的版本 og gcc)您还需要-std=c++11在命令行上。