std::basic_string_view<CharT,Traits>:: empty
From cppreference.net
<
cpp
|
string
|
basic string view
|
constexpr
bool
empty
(
)
const
noexcept
;
|
(自 C++17 起) | |
检查视图是否不包含任何字符,即判断
size()
==
0
是否成立。
目录 |
参数
(无)
返回值
true 表示视图为空, false 表示其他情况。
复杂度
常量。
示例
运行此代码
#include <iostream> #include <string_view> // 打印由单引号包围的字符串、 // 其长度以及是否被视为空。 void check_string(std::string_view ref) { std::cout << std::boolalpha << "'" << ref << "' has " << ref.size() << " character(s); emptiness: " << ref.empty() << '\n'; } int main(int argc, char **argv) { // 一个空字符串 check_string(""); // 几乎总是不为空:argv[0] if (argc > 0) check_string(argv[0]); }
可能的输出:
'' has 0 character(s); emptiness: true './a.out' has 7 character(s); emptiness: false
参见
|
返回字符数量
(公开成员函数) |
|
|
返回最大字符数量
(公开成员函数) |
|
|
(C++17)
(C++20)
|
返回容器或数组的大小
(函数模板) |
|
(C++17)
|
检查容器是否为空
(函数模板) |
|
检查字符串是否为空
(
std::basic_string<CharT,Traits,Allocator>
的公开成员函数)
|