std::basic_string<CharT,Traits,Allocator>::size, std::basic_string<CharT,Traits,Allocator>::length
cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| (1) | ||
size_type size() const; |
( C++11) | |
size_type size() const noexcept; |
( C++11) ( C++20) |
|
constexpr size_type size() const noexcept; |
( C++20) | |
| (2) | ||
size_type length() const; |
( C++11) | |
size_type length() const noexcept; |
( C++11) ( C++20) |
|
constexpr size_type length() const noexcept; |
( C++20) | |
CharT , .. std::distance(begin(), end()).
()
CharT .
|
|
( C++11) |
|
|
( C++11) |
std::string ( char), , , UTF-8.
#include <cassert>
#include <iterator>
#include <string>
int main()
{
std::string s("Exemplar");
assert(8 == s.size());
assert(s.size() == s.length());
assert(s.size() == static_cast<std::string::size_type>(
std::distance(s.begin(), s.end())));
std::u32string a(U""); // 8
assert(8 == a.size()); // 8 UTF-32
std::u16string b(u""); // 8
assert(8 == b.size()); // 8 UTF-16
std::string c(""); // 8
assert(24 == c.size()); // 24 UTF-8
#if __cplusplus >= 202002
std::u8string d(u8""); // 8
assert(24 == d.size()); // 24 UTF-8
#endif
}
| , (public -) | |
| (public -) | |
(C++17) |
(public - std::basic_string_view<CharT,Traits>)
|