这个问题在这里已经有了答案:
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/