"C++ 맵"의 두 판 사이의 차이

13번째 줄: 13번째 줄:
      
      
     for(auto it=m.begin(); it!=m.end(); it++) {
     for(auto it=m.begin(); it!=m.end(); it++) {
         cout << it->first << ":" << it->second << " ";
         cout << it->first << ':' << it->second << endl;
    }
}
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#include <iostream>
#include <map>
using namespace std;
 
int main() {
    map<string, int> m = {{"x",40}, {"y",-74}};
    for(auto& it: m) {
        cout << it.first << ':' << it.second << endl;
     }
     }
}
}

2023년 9월 10일 (일) 14:35 판

1 개요

C++ 맵
#include <iostream>
#include <map>
using namespace std;

int main() {
    map<string, int> m;
    m["x"] = 40;
    m["y"] = -74;
    
    for(auto it=m.begin(); it!=m.end(); it++) {
        cout << it->first << ':' << it->second << endl;
    }
}
#include <iostream>
#include <map>
using namespace std;

int main() {
    map<string, int> m = {{"x",40}, {"y",-74}};
    for(auto& it: m) {
        cout << it.first << ':' << it.second << endl;
    }
}

2 멤버 함수

3 같이 보기

4 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}