table of contents
std::basic_string::empty(3) | C++ Standard Libary | std::basic_string::empty(3) |
NAME¶
std::basic_string::empty - std::basic_string::empty
Synopsis¶
bool empty() const; (noexcept since C++11)
(constexpr since C++20)
Checks if the string has no characters, i.e. whether begin() == end().
Parameters¶
(none)
Return value¶
true if the string is empty, false otherwise
Complexity¶
Constant.
Example¶
// Run this code
#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";
}
Output:¶
s.empty():true s:''
s.empty():false s:'Exemplar'
s.empty():true s:''
See also¶
size returns the number of characters
length (public member function)
max_size returns the maximum number of characters
(public member function)
returns the number of characters that can be held in currently allocated
capacity storage
(public member function)
size
ssize returns the size of a container or array
(C++17) (function template)
(C++20)
empty checks whether the container is empty
(C++17) (function template)
empty checks whether the view is empty
(public member function of
std::basic_string_view<CharT,Traits>)
2024.06.10 | http://cppreference.com |