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