C++ String empty
This function verifies if the string is blank or not. It returns a Boolean outcome of either true or false.
Syntax
Consider a string str. Syntax would be:
str.empty();
Parameter
This function does not contain any parameter.
Return value
It produces a Boolean outcome of either 0 or 1 based on the specified conditions.
Example 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;}
Output:
String is empty
This example demonstrates how to verify if a string is empty or not by utilizing the empty function.
Example 2
#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:
String is not empty
This example verifies if the string is empty by utilizing the empty function.