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

标签 c++

这个问题在这里已经有了答案:





error: ‘i’ does not name a type with auto [duplicate]

(2 个回答)


5年前关闭。



#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: error: use of undeclared identifier 'tuple'

tuple x;

^

test.cpp:6:9: error: unexpected type name 'string': expected expression

tuple x;

    ^

test.cpp:7:3: error: use of undeclared identifier 'x'

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

^

test.cpp:7:7: error: use of undeclared identifier 'make_tuple'

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

  ^

test.cpp:8:11: error: reference to overloaded function could not be resolved; did you mean to call it? cout << get<0>x << endl << endl;



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

最佳答案

试试 #include <string> .

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

关于c++ - 为什么 g++ 不能编译元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090965/

相关文章:

c++ - 如何将我自己的文件关联添加到 "Open with"上下文菜单中?

c++ - 如果我使用框架,如何在另一台计算机上运行 mac exe?

c++ - cout C++ 期间出现堆错误

c++ - 如果您可以在 C++ 中将串行数据视为文件,那么 termios 的用途是什么?

c++ - 如何插入 std :bind as function pointer into constant map

c++ - 英特尔 TBB 中的原子 double / float

c++ - 在cmake文件中使用edje_cc

c++ - 如何确保函数在任何全局变量构造函数之前执行?

c++ - 我可以在另一个类中初始化一个类吗?

C++:getline在文件末尾卡住