本文共 1824 字,大约阅读时间需要 6 分钟。
stl中empty
"array" is a container which is used to create/container which is used to create/contains the fixed size arrays, the "array" in C++ STL is "class" actually and they are more efficient, lightweight and very easy to use, understand, "array" class contains many inbuilt functions, thus the implementation of the operations are fast by using this rather that C-Style arrays.
“数组”是用于创建/包含用于创建/包含固定大小的数组的容器,C ++ STL中的“数组 ”实际上是“类” ,它们更高效,轻巧且非常易于使用,可以理解, “数组”类包含许多内置函数,因此使用此数组而不是C-Style数组可以快速实现操作。
To use "array" class and its function, we need to include "array" class and its function, we need to include "array" header.
要使用“数组”类及其功能,我们需要包括“数组”类及其功能,我们需要包括“数组”标头。
empty() function is used to check whether an array is empty or not. It returns 1 (true), if the array size is 0 and returns 0 (false), if array size is not zero.
empty()函数用于检查数组是否为空。 如果数组大小为0,则返回1(真),如果数组大小不为零,则返回0(假)。
Syntax:
句法:
array_name.empty();
Parameters:
参数:
There is no parameter to be passed.
没有要传递的参数。
Return type:
返回类型:
1 (true) – if array is empty
1(true)–如果数组为空
0 (false) – if array is not empty
0(假)–如果数组不为空
Example:
例:
Input: arr1{} //an empty array arr2{10,20,30} //array with 3 elements Function calls: arr1.empty() arr2.empty() Output: 1 0
Program:
程序:
#include#include using namespace std;int main() { //declaring two arrays array arr1{ }; array arr2{ }; array arr3{ 10, 20, 30}; array arr4{ 10, 20, 30, 40, 50}; //printing arr_name.empty() value cout<<"arr1.empty(): "< <
Output
输出量
arr1.empty(): 1arr2.empty(): 0arr3.empty(): 0arr4.empty(): 0arr1 is emptyarr2 is not emptyarr3 is not emptyarr4 is not empty
翻译自:
stl中empty
转载地址:http://azozd.baihongyu.com/