名前空間
変種
操作

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

From cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
bool empty() const;
(C++11 以降 noexcept)
(C++20 以降 constexpr)

文字列に文字が含まれていないか、すなわち 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:''

[編集] 関連項目

文字数を返す
(public member function) [編集]
最大文字数を返す
(public member function) [編集]
現在割り当てられているストレージに保持できる文字数を返す
(public member function) [編集]
(C++17)(C++20)
コンテナまたは配列のサイズを返す
(関数テンプレート) [編集]
(C++17)
コンテナが空かどうかをチェックする
(function template) [編集]
ビューが空かどうかをチェックする
(std::basic_string_view<CharT,Traits> の public member function) [編集]
English 日本語 中文(简体) 中文(繁體)