没有操作员"<<&#;火柴

时间:2017-02-28 09:27:22

标签: c++ dictionary c++03

#include<iostream>
#include<set>
#include<unordered_map>

using namespace std;

typedef long Node;

typedef unordered_map<Node, set<Node> > Dothi;

Dothi g;

while (n--)
{
    Node u, i;
    int choose;
    cin >> choose;
    if (choose == 1)
    {
        cin >> u >> i;
        cout << (Lienke(u, i) ? "TRUE" : "FALSE");
    }

    checkCase2 = false;

    if (choose == 2)
    {
        cin >> u;
        for (  auto n = g[u].begin(); n!=g[u].end();++n)
        {
            cout << n <<" "; //Error here, cant cout n
            checkCase2 = true;
        }
  • 我不能在线下面:&#34; for(auto n = g [u] .begin(); n!= g [u] .end(); ++ n )&#34;

  • 它说:&#34;没有操作员&#34;&lt;&lt;&#;匹配这些操作数&#34;。

  • 我可以使用c ++ 2003

2 个答案:

答案 0 :(得分:3)

如果你想要的是在给定的迭代器下打印一个值,那么你必须在它上面使用dereference运算符:

cout << *n <<" ";
        ^ ~~~~ !

答案 1 :(得分:1)

您正在尝试打印迭代器n。由于未实现,因此会出现编译器错误。我认为你的内容如下:

std::cout << std::distance(g[u].begin(), n) << std::endl;

这将打印您正在使用的索引。您需要包含标题<iterator>

如果您要在该索引处打印元素(node又名long),那么请使用取消引用运算符(*),如下所示:

std::cout << *n << std::endl;

<强>更新

由于您使用的是C ++ 03,因此不允许auto关键字进行类型扣除。然后你应该使用(在for循环中声明n时):

Dothi::iterator n = g[u].begin();
相关问题