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.mzph.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…