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函数