为什么G 无法编译元组

Why is g++ not able to compile tuples?

本文关键字:编译 元组 为什么      更新时间:2023-10-16
#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;
}

我的程序遇到了困难,所以我写了一个简单的程序,即使这也不起作用。我不明白为什么在审查文档几次后遇到问题。它也可以在Xcode上编译罚款,但由于某种原因,它在G 上分解。

这是完整的错误消息:

test.cpp:6:3:错误:使用未宣布的标识符'tuple'

元组X;

^

test.cpp:6:9:错误:出乎意料的类型名称'string':预期 表达

元组X;

    ^

test.cpp:7:3:错误:使用未宣布的标识符'x'

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

^

test.cpp:7:7:错误:使用未宣布的标识符'make_tuple'

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

  ^

test.cpp:8:11:错误:引用过载函数不能是 解决;你是说要打电话吗?cout&lt;&lt;获取&lt; 0> x&lt;&lt;endl&lt;&lt;endl;

我使用的命令是G test.cpp

尝试#include <string>

可能(根据您的版本OG GCC),您还需要命令行上的-std=c++11

元组很好;您想让它成为的元组不是。

您没有#include <string>

因此,"字符串"一词对您的编译器没有意义,也不知道您要它做什么。它甚至无法说出您的意思是一种类型,因此不能说出您的意思是" tuple"一词,您的意思是" std :: tuple"。等等,等等&hellip;