在线文档教程
C++
字符串 | Strings

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:''

二次

另见

sizelengthreturns the number of characters (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/string/basic[医]字符串/空