名稱空間
變體
操作

std::basic_string_view<CharT,Traits>::empty

來自 cppreference.com
 
 
 
 
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> 的公共成員函式) [編輯]