std::basic_string<CharT,Traits,Allocator>::empty
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
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。
計算量
一定。
例
Run this code
#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:''
関連項目
| 文字数を返します (パブリックメンバ関数) |