这个 无序集合::空 在C++ STL中是一个内置函数,用于检查无序的集合容器是否为空。如果无序的_集容器为空,则返回True,否则返回False。
null
语法 :
map_name.empty()
参数: 此函数不接受任何参数。
返回值: 如果无序集合容器为空,则返回布尔值True,否则返回false。
以下程序说明了上述功能:
项目1:
// C++ program to illustrate the // unordered_set::empty function #include <iostream> #include <unordered_set> using namespace std; int main() { // declaration unordered_set< int > sample; // Check whether the unordered_set is empty if (sample.empty() == true ) cout << "true" << endl; else cout << "false" << endl; // Insert a value sample.insert(5); // Now check whether it is empty if (sample.empty() == true ) cout << "true" << endl; else cout << "false" << endl; return 0; } |
输出:
true false
项目2:
// C++ program to illustrate the // unordered_set::empty function #include <iostream> #include <unordered_set> using namespace std; int main() { // declaration unordered_set< int > uset; // Insert a value uset.insert({ 5, 6, 7, 8 }); // Check whether the unordered_set is empty if (uset.empty() == true ) cout << "true" << endl; else cout << "false" << endl; return 0; } |
输出:
false
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END