map简单应用
发布日期:2021-05-10 03:40:43 浏览次数:16 分类:精选文章

本文共 1407 字,大约阅读时间需要 4 分钟。

������������������������������������������������������������������������������������������������

1. ������

map
ma; // ������������������������������������������������
// ������������������
map
ma2(ma); // ���������������������������

2. ������������

// ������������������������
string a;
ma[a] = 1;
// ������pair������������
ma.insert(std::make_pair("string", 10));
// ������������������
map
ma2;
ma2["string2"] = 10;

3. ������

// ���������������
map
::iterator it;
// ������������������
for (it = ma.begin(); it != ma.end(); ++it) {
cout << (*it)->first << " -> " << it->second << endl;
}

4. ������������

// ���������������������
ma.erase(ma.begin());
// ������������������
string a;
ma.erase(a);

5. ������

string a;
auto pos = ma.find(a);
if (pos != ma.end()) {
// ���������������
} else {
// ���������
}

6. ������������

// ������������������
ma.size();
// ������������
ma.clear();
// ���������
ma.empty();
// ������������
ma.swap(ma2);
// ������������������������
if (ma.count("key")) {
// ���������1���0
} // ���������multimap���������������

7. ���������������

// ������������������
class Compare {
public:
bool operator()(const string& v1, const string& v2) {
return v1 > v2;
}
};
map
ma;

���������������������������������������������������������������������������������������������������������������������������

上一篇:扫雷游戏 and Java题解 <随缘学习>
下一篇:4月1日每日‘一’题(分数)

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月17日 02时41分01秒