std::basic_string_view<CharT,Traits>::empty
来自 cppreference.com
< cpp | string | basic string view
constexpr bool empty() const noexcept; |
(自 C++17 起) | |
检查视图是否没有字符,即 size() ==
0.
内容 |
[编辑] 参数
(无)
[编辑] 返回值
true 如果视图为空,否则为 false.
[编辑] 复杂度
常数。
[编辑] 示例
运行此代码
#include <iostream> #include <string_view> // Print a string surrounded by single quotes, its // length and whether it is considered empty. 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) { // An empty string check_string(""); // Almost always not empty: 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> 的公共成员函数) |