c++中 遍历map的三种方式

//遍历map的三种方式
//by 鸟哥

#include
#include
#include

using namespace std;

int main(){
    map m{};
    m[0]="aaa";
    m[1]="bbb";
    m[2]="ccc";

    map::iterator it;

    //方式一
    cout<<"方式一:"<::iterator iter = m.begin(); iter != m.end(); ++iter){
        cout<<"key:"<first<<" value:"<second<::iterator iter=m.begin();
    while(iter != m.end()){
        cout<<"key:"<first<<" value:"<second<

运行结果:

方式一:
key:0 value:aaa
key:1 value:bbb
key:2 value:ccc
方式二:
key:0 value:aaa
key:1 value:bbb
key:2 value:ccc
方式三:
key:0 value:aaa
key:1 value:bbb
key:2 value:ccc

你可能感兴趣的:(java,c++,开发语言,数据结构,后端)