小编Spr*_*ang的帖子

混淆使用c ++ STL迭代器

虽然我使用像这样的迭代器,

//include header files
using namespace std;

int main()
{
    map<int,int> intIntMap;
    map<int,int>::iterator pos;
    pos = intIntMap.begin();

    intIntMap[0] = 1;
    intIntMap[3] = 5;
    intIntMap[4] = 9;
    intIntMap[5] = 5;

    //??
    cout << (*pos).first << endl;

    while( pos != intIntMap.end() )
    {
        cout << pos->first << " <---> " << pos->second << endl;
        pos++;
    }

}
Run Code Online (Sandbox Code Playgroud)

输出为4;

但是我使用像这样的迭代器:

//include header file
using namespace std;

int main()
{
    map<int,int> intIntMap;
    map<int,int>::iterator pos;

    intIntMap[0] = 1;
    intIntMap[3] = 5;
    intIntMap[4] = 9;
    intIntMap[5] …
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl

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

标签 统计

c++ ×1

iterator ×1

stl ×1