久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果我在鍵不存在的情況下讀取地圖的值會發(fā)生

What happens if I read a map#39;s value where the key does not exist?(如果我在鍵不存在的情況下讀取地圖的值會發(fā)生什么?)
本文介紹了如果我在鍵不存在的情況下讀取地圖的值會發(fā)生什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

map<string, string> dada;
dada["dummy"] = "papy";
cout << dada["pootoo"];

我很困惑,因為我不知道它是否被認為是未定義的行為,如何知道我何時請求不存在的密鑰,我是否只使用 find ?

I'm puzzled because I don't know if it's considered undefined behaviour or not, how to know when I request a key which does not exist, do I just use find instead ?

推薦答案

map::operator[] 在數(shù)據(jù)結(jié)構(gòu)中搜索與給定鍵對應(yīng)的值,并返回對它的引用.

The map::operator[] searches the data structure for a value corresponding to the given key, and returns a reference to it.

如果它找不到一個,它會透明地為它創(chuàng)建一個默認的構(gòu)造元素.(如果您不想要這種行為,您可以改用 map::at 函數(shù).)

If it can't find one it transparently creates a default constructed element for it. (If you do not want this behaviour you can use the map::at function instead.)

您可以在此處獲取 std::map 方法的完整列表:

You can get a full list of methods of std::map here:

http://en.cppreference.com/w/cpp/container/map

這是當前 C++ 標準中 map::operator[] 的文檔...

Here is the documentation of map::operator[] from the current C++ standard...

  1. 效果:如果映射中沒有與 x 等效的鍵,則將 value_type(x, T()) 插入映射中.

  1. Effects: If there is no key equivalent to x in the map, inserts value_type(x, T()) into the map.

要求:key_type 應(yīng)為 CopyConstructible,mapped_type 應(yīng)為 DefaultConstructible.

Requires: key_type shall be CopyConstructible and mapped_type shall be DefaultConstructible.

返回:對 *this 中 x 對應(yīng)的映射類型的引用.

Returns: A reference to the mapped_type corresponding to x in *this.

復(fù)雜度:對數(shù).

T&運算符[](key_type&& x);

  1. 效果:如果映射中沒有與 x 等效的鍵,則將 value_type(std::move(x), T()) 插入映射中.

  1. Effects: If there is no key equivalent to x in the map, inserts value_type(std::move(x), T()) into the map.

要求:mapped_type 應(yīng)為 DefaultConstructible.

Requires: mapped_type shall be DefaultConstructible.

返回:對 *this 中 x 對應(yīng)的映射類型的引用.

Returns: A reference to the mapped_type corresponding to x in *this.

復(fù)雜度:對數(shù).

這篇關(guān)于如果我在鍵不存在的情況下讀取地圖的值會發(fā)生什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 在线亚洲人成电影网站色www | 国产精品不卡一区 | 91精品国产美女在线观看 | 国产伦精品一区二区三区在线 | 成人激情免费视频 | 欧美韩一区二区 | 一区二区三区免费 | 香蕉大人久久国产成人av | 婷婷中文字幕 | 99精品视频在线观看 | 久久久国产一区二区三区 | www.色53色.com| 精品视频一区二区三区在线观看 | 久久成人精品视频 | 欧美国产日韩一区二区三区 | 精品一二三区在线观看 | 国产精品成人久久久久 | 欧美综合在线视频 | 国产一区欧美一区 | 国产一区二区三区久久久久久久久 | 国产精品久久久久久二区 | 日韩欧美精品在线播放 | 激情一区二区三区 | 99热在线观看精品 | 国产精品日韩 | av一级久久 | 成在线人视频免费视频 | 中文字幕亚洲欧美 | 亚洲一区三区在线观看 | www.色综合| 午夜三级在线观看 | 91欧美激情一区二区三区成人 | 久久久久国产 | 国产精品夜夜夜一区二区三区尤 | 久久久久精 | 成人在线一级片 | 日本欧美黄色片 | 中文字字幕一区二区三区四区五区 | 亚洲精品欧美一区二区三区 | 中文字幕高清一区 | 欧美一区不卡 |