![]() |
In C++, strings are the sequence of characters that are stored as std::string class objects. In this article, we will learn how to check if a string is empty in C++ Example Input: str1="Hello! Geek" ; str2="" Output: str1 is not empty str2 is empty Checking if the String is Empty in C++To check for an empty string we can use the std::string::empty() function because what the empty function does is it checks for the length of a string and if the string is empty, it returns true, otherwise, it returns false. C++ Program to Check for Empty StringThe below example demonstrates the use of the empty function to check for empty string. C++
Output
str1 is not empty str2 is empty We can also use compare() and size() functions to check if string is empty. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |