std::basic_string_view<CharT,Traits>::size, std::basic_string_view<CharT,Traits>::length
From cppreference.com
< cpp | string | basic string view
| constexpr size_type size() const noexcept; |
(C++17以降) | |
| constexpr size_type length() const noexcept; |
(C++17以降) | |
ビュー内のCharT要素の数、つまり std::distance(begin(), end()) を返します。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
ビュー内のCharT要素の数。
[編集] 計算量
定数。
[編集] 例
このコードを実行
#include <iostream> #include <string_view> // Print a string surrounded by single quotes, its // length and whether it is considered empty. void check_string(std::string_view ref) { std::cout << std::boolalpha << "'" << ref << "' has " << ref.size() << " character(s); emptiness: " << ref.empty() << '\n'; } int main(int argc, char **argv) { // An empty string check_string(""); // Almost always not empty: argv[0] if (argc > 0) check_string(argv[0]); }
実行結果の例
'' has 0 character(s); emptiness: true './a.out' has 7 character(s); emptiness: false
[編集] 関連項目
| ビューが空かどうかをチェックする (public member function) | |
| 最大文字数を返す (public member function) | |
| 文字数を返す ( std::basic_string<CharT,Traits,Allocator> の public メンバ関数) |