C++ String empty
This function checks whether the string is empty or not. Function returns a Boolean value either true or false.
Syntax
Consider a string str. Syntax would be:
Example
str.empty();
Parameter
This function does not contain any parameter.
Return value
It returns a Boolean value either 0 or 1 depending upon the conditions.
Example 1
Example
#include<iostream>
using namespace std;
int main()
{
string str1;
if(str1.empty())
cout<<"String is empty";
else
cout<<"String is not empty";
return 0;}
Output:
Output
String is empty
This example shows how to check the string whether it is empty or not by using empty function.
Example 2
Example
#include<iostream>
using namespace std;
int main()
{
string str1="Hello javaCppTutorial";
if(str1.empty())
cout<<"String is empty";
else
cout<<"String is not empty";
return 0;
}
Output:
Output
String is not empty
This example checks whether the string is empty or not by using empty function.