std::basic_string<CharT,Traits,Allocator>::empty
From cppreference.com
< cpp | string | 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) |