![]() |
VOOZH | about |
The std::string::empty() function in C++ is a predefined member function of the std::string class template. This function is used to check if a string is empty, i.e., whether its length is 0 or not, and returns a boolean value true if the string is empty otherwise, it returns false.
stringObj.empty();Here, stringObj is the name of the string object.
The std::string::empty() function does not take any parameters.
The return value of the std::string::empty() tells us whether the string is empty or not.
true if the string length is 0, otherwise,Input:
str1="GeeksforGeeks
str2=""
Output:
str1 is not empty
str2 is empty
The below example illustrates how we can use an empty() function to check if the given string is empty or not in C++.
str1 is not empty str2 is empty
Time Complexity: O(1)
Auxilliary Space: O(1)