【问题标题】:Why is this error coming? [closed]为什么会出现这个错误? [关闭]
【发布时间】:2014-10-02 15:38:45
【问题描述】:

我有以下代码,我在标准模板库中使用 c++11 元组。

    #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() ; 
    }

显示错误

Expected primary expression before '>' token. on the line `tuple<string,string,string,string,string,string> tup = make_tuple(t1,t2,t3,t4,t5,t6);` 

谁能告诉我为什么会出现这个编译器错误。

【问题讨论】:

  • 这不是完整的代码,或者您发布了其他内容。
  • @ps06756: 如果有,请添加标题和取消命名空间声明
  • 你启用-std=c++11了吗?
  • @谢谢,这就是问题所在。非常感谢
  • @ps06756 tuple 与带有命名数据的 class 中的 6 个无名字段。 class 可能在设计和使用上比通用的无名 tuple 更清晰。

标签: c++ c++11 compiler-errors tuples


【解决方案1】:

由于您包含了所有标头并定义了所有函数,因此您很可能错过了启用 C++11 标志

你需要使用-std=c++11标志编译

【讨论】:

  • 错误提示在哪里?
  • @interjay 抱歉,当我看到 ...primary expression before '&gt;' 的东西时,我认为它可能是 -std=C++11,因为在嵌套模板中使用了 &gt; &gt;。同意这是一个盲目的猜测
  • 奇怪,我认为缺少 c++11 会更早导致错误,例如在#include &lt;tuple&gt;。但 OP 似乎证实这有帮助。
猜你喜欢
  • 2020-02-09
  • 2023-04-04
  • 2020-02-03
  • 1970-01-01
  • 1970-01-01
  • 2020-11-26
  • 2016-01-08
  • 2018-02-23
相关资源
最近更新 更多