當前位置:
首頁 >
map下标操作
發布時間:2025/6/15
43
豆豆
? ? ? ? ? ? ? ???強烈推薦人工智能學習網站??
? ? ? ? ? ? ? 之前提到過有關map下標操作,但是今天這個更復雜一點了,寫下來學習一下。
struct Node {int a;int b; };int main() {map<int, Node> mapTest = { { 1,{ 11, 111}} , { 2, { 22, 222 }}};map<int, Node>::iterator IT;IT=mapTest.find(2);//find函數返回一個迭代器if (mapTest.end() != mapTest.find(1)){cout << IT->second.a;}cout << mapTest[2].a << endl;printf("%d\n",mapTest[1].b/mapTest[1].a);//正確用法mapTest[1].a += 4;cout << mapTest[1].a;//正確用法return 0; }打印:22
?
? ? ? ? ? ? 22
? ? ? ? ? ? 10
? ? ? ? ? ? 15
如何找出22這個位置對于的值,上述代碼中給出了2種方法。今天工作中,有人說cout<<mapTest[1].a;是錯誤用法,現在測試了一下,發現是正確的。
?
? ? ? ? ?
?
?
總結
- 上一篇: sprintf,sscanf,snpri
- 下一篇: string操作小汇总