std::basic_string<CharT,Traits,Allocator>::empty
ja.cppreference.net より
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)
|
コンテナまたは配列のサイズを返す
(function template) |
|
(C++17)
|
コンテナが空かどうかをチェックする
(function template) |
|
ビューが空かどうかをチェックする
(public member function of
std::basic_string_view<CharT,Traits>
)
|