小编Lia*_*Met的帖子

无法理解“list<int>::iterator i;”

我一直在研究如何使列表在 C++ 中工作。尽管第 12 行不起作用,但我对标题中提到的行更感兴趣,因为我不明白这是做什么的?

因此,for循环中存在错误,但我认为这是由于我对 缺乏了解list<int>::iterator i;,如果有人能够分解并解释这条线对我意味着什么,那就太棒了!

#include <iostream>
#include <list>

using namespace std;

int main(){

    list<int> integer_list;

    integer_list.push_back(0); //Adds a new element to the end of the list.
    integer_list.push_front(0); //Adds a new elements to the front of the list.
    integer_list (++integer_list.begin(),2); // Insert '2' before the position of first argument.

    integer_list.push_back(5);
    integer_list.push_back(6);

    list <int>::iterator i;

    for (i = integer_list; i != integer_list.end(); ++i)
    {
        cout << *i << " ";
    }


    return 0;

} …
Run Code Online (Sandbox Code Playgroud)

c++ iterator list

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

标签 统计

c++ ×1

iterator ×1

list ×1