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

来自cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
bool empty() const;
(C++11 起为 noexcept)
(C++20 起为 constexpr)

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

目录

[编辑] 参数

(无)

[编辑] 返回值

若字符串为空则为 true,否则为 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:''

[编辑] 参阅

返回字符数
(公开成员函数) [编辑]
返回字符数的最大值
(公开成员函数) [编辑]
返回当前对象分配的存储空间能保存的字符数量
(公开成员函数) [编辑]
(C++17)(C++20)
返回容器或数组的大小
(函数模板) [编辑]
(C++17)
检查容器是否为空
(函数模板) [编辑]
检查视图是否为空
(std::basic_string_view<CharT,Traits> 的公开成员函数) [编辑]