名前空間
変種
操作

std::basic_string<CharT,Traits,Allocator>::empty

提供: cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
bool empty() const;
(C++11未満)
bool empty() const noexcept;
(C++11以上)
(C++20未満)
[[nodiscard]] constexpr bool empty() const noexcept;
(C++20以上)

文字列が文字を持っていない、すなわち 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:''

[編集] 関連項目

文字数を返します
(パブリックメンバ関数) [edit]