亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 36113 | 回復(fù): 8
打印 上一主題 下一主題

[C++] c++ map 相同key不會覆蓋? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2014-02-28 22:12 |只看該作者 |倒序?yàn)g覽
#include <map>
#include <string>
#include <iostream>
using namespace std;

map<int, string> mapStudent;
int main() {
    mapStudent.insert(pair<int, string>(3, "student_one"));
    mapStudent.insert(pair<int, string>(3, "student_tw"));
    mapStudent.insert(pair<int, string>(3, "student_three"));
    map<int, string>::iterator  iter;
    iter = mapStudent.find(3);
    printf("%s\n", iter->second.c_str());
    return 0;
}

執(zhí)行結(jié)果是:student_one

為什么后續(xù)插入的沒有覆蓋最初插入的呢?
我聽說是會覆蓋的

剛接觸C++
請大家指教一下了

論壇徽章:
5
獅子座
日期:2013-08-20 10:12:24午馬
日期:2013-11-23 18:04:102015年辭舊歲徽章
日期:2015-03-03 16:54:152015亞冠之德黑蘭石油
日期:2015-06-29 18:11:1115-16賽季CBA聯(lián)賽之新疆
日期:2024-02-21 10:00:53
2 [報告]
發(fā)表于 2014-02-28 22:23 |只看該作者
Because element keys in a map are unique, the insertion operation checks whether each inserted element has a key equivalent to the one of an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element (if the function returns a value).


十個字補(bǔ)丁……

論壇徽章:
1
2015年辭舊歲徽章
日期:2015-03-03 16:54:15
3 [報告]
發(fā)表于 2014-02-28 22:45 |只看該作者
map -->> multimap

論壇徽章:
17
處女座
日期:2013-08-27 09:59:352015亞冠之柏太陽神
日期:2015-07-30 10:16:402015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-07-29 18:58:182015年亞洲杯之巴勒斯坦
日期:2015-03-06 17:38:17摩羯座
日期:2014-12-11 21:31:34戌狗
日期:2014-07-20 20:57:32子鼠
日期:2014-05-15 16:25:21亥豬
日期:2014-02-11 17:32:05丑牛
日期:2014-01-20 15:45:51丑牛
日期:2013-10-22 11:12:56雙子座
日期:2013-10-18 16:28:17白羊座
日期:2013-10-18 10:50:45
4 [報告]
發(fā)表于 2014-03-01 10:15 |只看該作者
回復(fù) 1# tianhailong

insert時相同的key不會被覆蓋,你想表達(dá)的應(yīng)該是下標(biāo)訪問表達(dá)式,map[key] =value;這樣的調(diào)用是會被重寫相應(yīng)key的值的。
   

論壇徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
5 [報告]
發(fā)表于 2014-03-03 13:07 |只看該作者
Because element keys in a map are unique, the insertion operation checks whether each inserted element has a key equivalent to the one of an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element (if the function returns a value).
樓主不看二樓的回復(fù)!

論壇徽章:
0
6 [報告]
發(fā)表于 2014-03-03 19:13 |只看該作者
當(dāng)遇到相同的鍵值時無法插入,所以也就無法覆蓋了

論壇徽章:
4
雙子座
日期:2014-08-28 10:08:002015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:58:112015年亞洲杯之阿聯(lián)酋
日期:2015-03-13 03:25:15
7 [報告]
發(fā)表于 2014-03-03 19:25 |只看該作者
map的insert是有返回值的,insert重復(fù)的會有錯誤,這個技巧在面試如何找出2個數(shù)組相同的數(shù)字的時候有奇效

論壇徽章:
89
水瓶座
日期:2014-04-01 08:53:31天蝎座
日期:2014-04-01 08:53:53天秤座
日期:2014-04-01 08:54:02射手座
日期:2014-04-01 08:54:15子鼠
日期:2014-04-01 08:55:35辰龍
日期:2014-04-01 08:56:36未羊
日期:2014-04-01 08:56:27戌狗
日期:2014-04-01 08:56:13亥豬
日期:2014-04-01 08:56:02亥豬
日期:2014-04-08 08:38:58程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-05 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-07 06:20:00
8 [報告]
發(fā)表于 2014-03-03 21:00 |只看該作者
回復(fù) 7# weishuo1999

應(yīng)該是排序之后遍歷更快吧。


   

論壇徽章:
1
雙子座
日期:2014-04-20 13:05:34
9 [報告]
發(fā)表于 2014-03-03 21:46 |只看該作者
C++ STL 的實(shí)現(xiàn):
1.vector  底層數(shù)據(jù)結(jié)構(gòu)為數(shù)組 ,支持快速隨機(jī)訪問
2.list    底層數(shù)據(jù)結(jié)構(gòu)為雙向鏈表,支持快速增刪
3.deque   底層數(shù)據(jù)結(jié)構(gòu)為一個中央控制器和多個緩沖區(qū),詳細(xì)見STL源碼剖析P146,支持首尾(中間不能)快速增刪,也支持隨機(jī)訪問
4.stack   底層一般用23實(shí)現(xiàn),封閉頭部即可,不用vector的原因應(yīng)該是容量大小有限制,擴(kuò)容耗時
5.queue   底層一般用23實(shí)現(xiàn),封閉頭部即可,不用vector的原因應(yīng)該是容量大小有限制,擴(kuò)容耗時
6.45是適配器,而不叫容器,因?yàn)槭菍θ萜鞯脑俜庋b
7.priority_queue 的底層數(shù)據(jù)結(jié)構(gòu)一般為vector為底層容器,堆heap為處理規(guī)則來管理底層容器實(shí)現(xiàn)
8.set       底層數(shù)據(jù)結(jié)構(gòu)為紅黑樹,有序,不重復(fù)
9.multiset  底層數(shù)據(jù)結(jié)構(gòu)為紅黑樹,有序,可重復(fù)
10.map      底層數(shù)據(jù)結(jié)構(gòu)為紅黑樹,有序,不重復(fù)
11.multimap 底層數(shù)據(jù)結(jié)構(gòu)為紅黑樹,有序,可重復(fù)
12.hash_set 底層數(shù)據(jù)結(jié)構(gòu)為hash表,無序,不重復(fù)
13.hash_multiset 底層數(shù)據(jù)結(jié)構(gòu)為hash表,無序,可重復(fù)
14.hash_map      底層數(shù)據(jù)結(jié)構(gòu)為hash表,無序,不重復(fù)
15.hash_multimap 底層數(shù)據(jù)結(jié)構(gòu)為hash表,無序,可重復(fù)

from
http://blog.csdn.net/huangkq1989/article/details/7277282
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP