C++ 为什么会出现这种错误?
我有以下代码,我正在使用标准模板库中的c++11元组C++ 为什么会出现这种错误?,c++,c++11,compiler-errors,tuples,C++,C++11,Compiler Errors,Tuples,我有以下代码,我正在使用标准模板库中的c++11元组 #include <tuple> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <functional> #include <string> using namespace std ; vector<tupl
#include <tuple>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
using namespace std ;
vector<tuple<string,string,string,string,string,string> > lst ;
int main()
{
string t1,t2,t3,t4,t5,t6 ;
cin>>t1>>t2>>t3>>t4>>t5>>t6 ;
char c ;
tuple<string,string,string,string,string,string> tup = make_tuple(t1,t2,t3,t4,t5,t6);
while(!feof(stdin))
{
list.push_back(tup) ;
cin>>t1 ;
cin>>t2 ;
cin>>t3 ;
cin>>t4 ;
cin>>t5 ;
cin>>t6 ;
tup = make_tuple(t1,t2,t3,t4,t5,t6) ;
getchar_unlocked() ;
getchar_unlocked() ;
}
sort(list.begin(), list.end(), mySort) ;
print() ;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
向量lst;
int main()
{
串t1、t2、t3、t4、t5、t6;
cin>>t1>>t2>>t3>>t4>>t5>>t6;
字符c;
tuple tup=make_tuple(t1、t2、t3、t4、t5、t6);
而(!feof(stdin))
{
列表。推回(tup);
cin>>t1;
cin>>t2;
cin>>t3;
cin>>t4;
cin>>t5;
cin>>t6;
tup=生成tuple(t1、t2、t3、t4、t5、t6);
getchar_unlocked();
getchar_unlocked();
}
排序(list.begin()、list.end()、mySort);
打印();
}
它显示了错误
Expected primary expression before '>' token. on the line `tuple<string,string,string,string,string,string> tup = make_tuple(t1,t2,t3,t4,t5,t6);`
在'>'标记之前应该有主表达式。在“tuple tup=make_tuple(t1,t2,t3,t4,t5,t6)”行上,`
谁能告诉我为什么编译器会出错 由于您包含了所有的头并定义了所有的函数,很有可能您没有启用C++11标志
您需要使用
-std=c++11
标志进行编译这不是完整的代码,或者您发布了其他内容。@ps06756:请添加标题并取消名称空间声明(如果有的话)。是否启用了-std=c++11
?@谢谢,这就是问题所在。谢谢lot@ps06756在元组
中有6个无名字段,而在类
中有命名数据。一个类
在设计和使用上可能比一个通用的无名的元组
更清晰。这个错误表明了什么?@interjay抱歉,当我看到一些…在'>'之前的主要表达式
时,我假设它可能是-std=C++11
,因为>
在嵌套模板中的使用。同意这是一个盲目的猜测。奇怪的是,我认为缺少c++11会导致早期的错误,例如在#include
中。但OP似乎证实了这一点。