stl中map函數_map :: empty()函數以及C ++ STL中的Example

stl中map函數

C ++ STL映射:: empty() (C++ STL map::empty())

It is built-in function in C++ STL and used to check whether the map container is empty or not i.e whether its size is 0 or not?

它是C ++ STL中的內置函數,用于檢查地圖容器是否為空,即其大小是否為0?

Syntax:

句法:

    myMap.empty()

Where, myMap is the object of class map.

其中, myMap是類映射的對象。

Parameters: None - It does not accept any parameters.

參數:無-不接受任何參數。

Return value: It returns True, if map is empty and returns False, otherwise.

返回值:如果map為空,則返回True,否則返回False。

Example:

例:

#include <iostream> 
#include <map> 
using namespace std; 
int main() {
// Example of Non Empty map
map<char, string> myMap; 
myMap['i'] = "include"; 
myMap['h'] = "help"; 
if (myMap.empty()) { 
cout << "myMap is Empty !!"; 
} 
else { 
cout << "myMap contains elements , Not Empty!!"; 
} 
cout<<endl<<endl;
// Example of Empty map
map<char, int> empMap; 
if (empMap.empty()) { 
cout << "empMap is Empty !!"; 
} 
else { 
cout << "empMap contains elements , Not Empty!!"; 
} 
return 0;     
} 

Output

輸出量

myMap contains elements , Not Empty!!
empMap is Empty !!

翻譯自: https://www.includehelp.com/stl/map-empty-function-with-example-in-cpp-stl.aspx

stl中map函數

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379233.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379233.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379233.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C#使用Dotfuscator混淆代碼以及加密

C#編寫的代碼如果不進行一定程度的混淆和加密&#xff0c;那么是非常容易被反編譯進行破解的&#xff0c;特別是對于一些商業用途的C#軟件來說&#xff0c;因為盯著的人多&#xff0c;更是極易被攻破。使用Dotfuscator可以實現混淆代碼、變量名修改、字符串加密等功能。 這里介…

操作列表(三)

1&#xff0c;for循環(for 變量名 in 列表名:) phone [iphone 8, xiaomi10pro, huaweiv30pro, honor20, jianguopro]#定義一個列表phone for tel in phone:print("手機的類型為&#xff1a;" tel.title())#當然這里的每個元素也可以調用title()等一些方法 print(&…

C#特性之通俗演義

首先要說的是&#xff0c;可能一些剛接觸C#的朋友常常容易把屬性&#xff08;Property&#xff09;跟特性&#xff08;Attribute&#xff09;弄混淆&#xff0c;其實這是兩種不同的東西。屬性就是面向對象思想里所說的封裝在類里面的數據字段&#xff0c;其形式為&#xff1a; …

棧應用_計算按運算符優先級分布的算式(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; LinkList.h LinkList.c LinkStack.h LinkStack.c 棧-線性表 main.c #include <stdio.h> #include "LinkStack.h"//該程序用棧來計算算式 /*比如&#xff1a;1*56/(5-3)…

php globals_PHP $ GLOBALS(超級全局變量),帶有示例

php globalsPHP $全球 (PHP $GLOBALS) PHP $GLOBALS is the only superglobal that does not begin with an underscore (_). It is an array that stores all the global scope variables. PHP $ GLOBALS是唯一不以下劃線( _ )開頭的超全局變量。 它是一個存儲所有全局范圍變量…

安裝部署項目(轉自)

1 新建安裝部署項目 打開VS&#xff0c;點擊新建項目&#xff0c;選擇&#xff1a;其他項目類型->安裝與部署->安裝向導(安裝項目也一樣)&#xff0c;然后點擊確定。 2 安裝向導 關閉后打開安裝向導&#xff0c;點擊下一步&#xff0c;或者直接點擊完成。 3 開始制作…

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

更改jdk&#xff0c;版本過高的緣故&#xff0c;更改jdk為1.7版本

kotlin 查找id_Kotlin程序查找給定范圍內的素數

kotlin 查找idA prime number is a natural number that is greater than 1 and cannot be formed by multiplying two smaller natural numbers. 質數是大于1的自然數&#xff0c;不能通過將兩個較小的自然數相乘而形成。 Given a range start and end, we have to print al…

socket代碼

客戶端:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <sys/socket.h> int main(int argc,char *argv[]) {int sockfd,numbytes;char buf[100];struct sockaddr_in th…

棧應用_將算式轉成按運算符優先級分布(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; LinkList.h LinkList.c LinkStack.h LinkStack.c 棧-線性表 main.c #include <stdio.h> #include "LinkStack.h"/* 該程序將 正常的算式 轉換成按照運算符優先分布的算式…

課堂筆記(一)

1&#xff0c;怎樣查詢函數的用法 help(函數名) 2&#xff0c;表達式float(0b1100010101)float(0o1425)float(0x315)的結果是什么&#xff0c;并說明原因 True 浮點類型的數用二進制八進制十六進制的不同表達 3&#xff0c;oct()方法 轉換八進制輸出 4&#xff0c;hex()方…

Struts2.0標簽使用之s:checkboxlist/

jsp代碼如下&#xff1a; <s:form action"receive.action" method"post"> <s:checkboxlist id"user" name"cheuser" list"#request.userlist" listKey"id" listValue"name" lab…

[轉]深入淺出Java設計模式之備忘錄模式

本文轉自&#xff1a;http://dev.yesky.com/450/2070450.shtml 一、引子   俗話說&#xff1a;世上難買后悔藥。所以凡事講究個“三思而后行”&#xff0c;但總常見有人做“痛心疾首”狀&#xff1a;當初我要是……。如果真的有《大話西游》中能時光倒流的“月光寶盒”&#…

遞歸問題(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; main.c #include <stdio.h>//該程序使用遞歸將字符串從后往前依次輸出void reverse(char* s) {if( (s ! NULL) && (*s ! \0) ){reverse(s 1);printf("%c", *s);…

Java LocalDate類| ofYearDay()方法與示例

LocalDate類的YearDay()方法 (LocalDate Class ofYearDay() method) ofYearDay() method is available in java.time package. ofYearDay()方法在java.time包中可用。 ofYearDay() method is used to create an instance of LocalDate object that holds the value from the ye…

ASP.NET C#讀寫Cookie的方法!

Cookie (HttpCookie的實例)提供了一種在 Web 應用程序中存儲用戶特定信息的方法。例如&#xff0c;當用戶訪問您的站點時&#xff0c;您可以使用 Cookie 存儲用戶首選項或其他信息。當該用戶再次訪問您的網站時&#xff0c;應用程序便可以檢索以前存儲的信息。 創建Cookie方法…

遞歸-裴波那契數列(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; main.c #include <stdio.h>//該程序輸出裴波那契數列 int fibonacci(int n) {if( n > 1 ){return fibonacci(n-1) fibonacci(n-2);//注意&#xff1a;這里調用是一直調用左邊函…

javascript 事件委派

javascript 模擬用戶操作 <a href"javascript:;" onClick"javascript:alert(131231);" id"abc">asdfasdf</a> <script> if(document.all) { document.getElementById(abc).fireEvent(onclick); } else { var evt document.cr…

Java Duration類| isNegative()方法與示例

持續時間類isNegative()方法 (Duration Class isNegative() method) isNegative() method is available in java.time package. isNegative()方法在java.time包中可用。 isNegative() method is used to check whether this Duration object holds the value of length < 0 …

經典例題(一)

1&#xff0c;已知復數 x 6 8j 請寫出它的模、實部、虛部及共軛復數的命令&#xff0c;并寫出運行結果。 X 6 8j print("模為:%d"% abs(X)) print("實部為:%s"% X.real) print("虛部為:%s"% X.imag) print("共軛復數為:%s"% X.co…