命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
bool empty() const;
(noexcept since C++11) (C++11 起无异常抛出)
(constexpr since C++20) (C++20 起为 constexpr)

检查字符串是否没有字符,即是否 begin() == end()

内容

[编辑] 参数

(无)

[编辑] 返回值

true 如果字符串为空,false 否则为 false

[编辑] 复杂度

常数。

[编辑] 示例

#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";
}

输出

s.empty():true   s:''
s.empty():false  s:'Exemplar'
s.empty():true   s:''

[编辑] 参见

返回字符数
(public member function) [编辑]
返回最大字符数
(public member function) [编辑]
返回当前已分配存储中可容纳的字符数
(public member function) [编辑]
(C++17)(C++20)
返回容器或数组的大小
(function template) [编辑]
(C++17)
检查容器是否为空
(function template) [编辑]
检查视图是否为空
(public member function of std::basic_string_view<CharT,Traits>) [编辑]