C++ 맵

Jmnote (토론 | 기여)님의 2024년 1월 15일 (월) 19:53 판 (→‎개요)

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;
    }
}
#include <iostream>
#include <map>
using namespace std;

int main() {
    map<string, int> m = {{"x",40}, {"y",-74}};
    cout << m["foo"];
}

2 멤버 함수

3 같이 보기

4 참고

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