STL map example
1615 단어 example
#include <string.h>
#include <iostream>
#include <map>
#include <utility>
using namespace std;
struct cmp_str
{
bool operator()(char const *a, char const *b)
{
return std::strcmp(a, b) < 0;
}
};
int main()
{
map<char *, int, cmp_str> Employees;
// Examples of assigning Map container contents
// 1) Assignment using array index notation
Employees["Mike C."] = 5234;
Employees["Charlie M."] = 3374;
// 2) Assignment using member function insert() and STL pair
Employees.insert(std::pair<char *,int>("David D.",1923));
// 3) Assignment using member function insert() and "value_type()"
Employees.insert(map<char *,int>::value_type("John A.",7582));
// 4) Assignment using member function insert() and "make_pair()"
Employees.insert(std::make_pair((char *)"Peter Q.",5328));
cout << "Map size: " << Employees.size() << endl;
for( map<char *, int, cmp_str>::iterator ii=Employees.begin(); ii!=Employees.end(); ++ii)
{
cout << (*ii).first << ": " << (*ii).second << endl;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단한 Golang HTTP 서버 예제Go에서 HTTP 서버를 만드는 것은 다음과 같이 간단합니다. http.ListenAndServe(":8222", nil) 여기서 우리는 머신의 8222 포트에서 요청을 수신하는 간단한 서버를 만들었습니다. 이것은 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.