String Empty Function - C++ Programming Tutorial
C++ Course / Strings / String Empty Function

String Empty Function

BLUF: Mastering String Empty Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: String Empty Function

C++ is renowned for its efficiency. Learn how String Empty Function enables low-level control and high-performance computing in the tutorial below.

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:

Example

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

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 demonstrates how to verify if a string is empty or not by utilizing the 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 verifies if the string is empty by utilizing the empty function.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience