C++ String empty()
C++ String empty()
此函数检查字符串是否为空。函数返回布尔值true或false。
语法
考虑字符串str。语法为:
参数
此函数不包含任何参数。
返回值
它返回布尔值视情况而定,取值为0或1、
示例1
#include<iostream>
using namespace std;
int main()
{
string str1;
if(str1.empty())
cout<<"String is empty";
else
cout<<"String is not empty";
return 0;}
输出:
此示例显示如何通过使用empty()函数检查字符串是否为空。
示例2
#include<iostream>
using namespace std;
int main()
{
string str1="Hello lidihuo";
if(str1.empty())
cout<<"String is empty";
else
cout<<"String is not empty";
return 0;
}
输出:
此示例通过使用empty()函数检查字符串是否为空。