小编Akr*_*med的帖子

it.first 和 it->first 有什么区别?

for(auto it = M.begin(); it!=M.end();it++)
    {
        cout<<it->first<<" "<<it->second<<"\n";  
    }
Run Code Online (Sandbox Code Playgroud)

上面的代码工作得很好但是,

    for(auto it : M)
    {
        if(it->second == 1) return it->first;
    }
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误。

为什么我必须使用it.secondandit.first而不是it->secondand it->first

c++ hashmap c++11

2
推荐指数
1
解决办法
251
查看次数

为什么在链表中创建当前变量时不使用“new”?

这是打印链表元素的解决方案。

为什么不是Node *current = new Node;然后current = head;呢?

void printLinkedList(Node* head)
{
    Node *current = head;    
    while(current!=NULL){
        cout << current -> data << endl;
        current = current -> next;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers linked-list new-operator data-structures

1
推荐指数
1
解决办法
73
查看次数