std::basic_string<CharT,Traits,Allocator>::empty
来自cppreference.com
<tbody>
</tbody>
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> 的公开成员函数)
|