判断map容器是否为空
可以使用empty()函数判断map容器是否为空,若容器为空则返回true,否则返回false。示例代码如下:
#include <iostream>
#include <map>
int main() {
std::map<int, std::string> myMap; // 定义一个空的map容器
if (myMap.empty()) { // 判断map容器是否为空
std::cout << "myMap is empty." << std::endl;
} else {
std::cout << "myMap is not empty." << std::endl;
}
return 0;
}
输出结果为:
myMap is empty.
原文地址: https://www.cveoy.top/t/topic/hucS 著作权归作者所有。请勿转载和采集!