为什么G 无法编译元组
Why is g++ not able to compile tuples?
#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;
相关文章:
- C++:TypeDef使用元组
- Pybind11:将元组列表从Python传递到C++
- 如何在编译时将齐次元组转换为数组?
- 验证(使用 static_assert)元组类型是否遵循某种顺序(有状态编译时检查)
- 将树转换为元组的编译时转换
- 具有多个空成员的 std::元组上的比较无法在 GCC 上编译
- 编译时排序的异构元组
- 编译按映射类型获取元素的映射错误元组
- 为什么不提升元组运算符 == 并<<编译?
- 使用GCC v4.8在Ubuntu 14.04上定义C 11中元组向量时的编译错误
- 为什么G 无法编译元组
- 提升元组和 stl 向量编译错误
- 元组中类型的编译时重新排列
- 使用可变参数模板制作类似元组的编译时"linked-list"
- 任意但编译时已知的类型数的元组
- 如何在编译时替换元组元素
- 在编译时对已知N的std::元组重复
- 在编译时产生相同类型的std::元组,给定其长度,由模板参数提供
- 编译问题:使用元组构建Composite_Key可变模板类
- 元组和可变参数模板的编译问题