std::basic_string::empty
| bool empty() const; |  |  | 
|---|
检查字符串是否没有字符,即是否begin() == end()...
参数
%280%29
返回值
true如果字符串是空的,false否则。
例外
| (none) | (until C++11) | 
|---|---|
| noexcept specification: noexcept | (since C++11) | 
复杂性
常量。
例
二次
#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:''二次
另见
| sizelength | returns the number of characters (public member function) | 
|---|
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

