std::basic_string<CharT,Traits,Allocator>::empty
來自 cppreference.com
< cpp | string | basic_string
bool empty() const; |
(C++11 起無異常丟擲) (C++20 起為 constexpr) |
|
檢查字串是否不包含任何字元,即 begin() == end()。
目錄 |
[edit] 引數
(無)
[edit] 返回值
如果字串為空,則為 true,否則為 false
[edit] 複雜度
常數時間。
[edit] 示例
執行此程式碼
#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:''
[edit] 參閱
返回字元數 (public member function) | |
返回字元的最大數量 (public member function) | |
返回當前分配儲存中可容納的字元數 (public member function) | |
(C++17)(C++20) |
返回容器或陣列的大小 (function template) |
(C++17) |
檢查容器是否為空 (function template) |
檢查檢視是否為空 ( std::basic_string_view<CharT,Traits> 的公共成員函式) |