std::basic_string<CharT,Traits,Allocator>::empty

Checks if the string has no characters, i.e. whether begin() == end().

# Declarations

bool empty() const;

(noexcept since C++11) (constexpr since C++20)

# Return value

true if the string is empty, false otherwise

# Example

#include <iostream>
#include <string>
 
int main()
{
    std::string s;
    std::boolalpha(std::cout);
    std::cout << "s.empty():" << s.empty() << "\t s:'" << s << "'\n";
 
    s = "Exemplar";
    std::cout << "s.empty():" << s.empty() << "\t s:'" << s << "'\n";
 
    s = "";
    std::cout << "s.empty():" << s.empty() << "\t s:'" << s << "'\n";
}

# See also