std::basic_string<CharT,Traits,Allocator>::size, (3) - Linux Manuals
std::basic_string<CharT,Traits,Allocator>::size,: std::basic_string<CharT,Traits,Allocator>::size,
Command to display std::basic_string<CharT,Traits,Allocator>::size,
manual in Linux: $ man 3 std::basic_string<CharT,Traits,Allocator>::size,
NAME
std::basic_string<CharT,Traits,Allocator>::size, - std::basic_string<CharT,Traits,Allocator>::size,
Synopsis
size_type size() const; (until C++11)
size_type size() const noexcept; (since C++11)
size_type length() const; (until C++11)
size_type length() const noexcept; (since C++11)
Returns the number of CharT elements in the string, i.e. std::distance(begin(),
end()).
Parameters
(none)
Return value
The number of CharT elements in the string.
Complexity
Unspecified (until C++11)
Constant (since C++11)
Notes
For std::string, the elements are bytes (objects of type char), which are not the
same as characters if a multibyte encoding such as UTF-8 is used.
Example
// Run this code
#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 code points
assert(8 == a.size()); // 8 code units in UTF-32
std::u16string b(u"ハロー・ワールド"); // 8 code points
assert(8 == b.size()); // 8 code units in UTF-16
std::string c(u8"ハロー・ワールド"); // 8 code points
assert(24 == c.size()); // 24 code units in UTF-8
}
See also
empty checks whether the string is empty
(public member function)
max_size returns the maximum number of characters
(public member function)
Pages related to std::basic_string<CharT,Traits,Allocator>::size,
- std::basic_string<CharT,Traits,Allocator>::size,std::basic_string<CharT,Traits,Allocator>::length (3) - std::basic_string<CharT,Traits,Allocator>::size,std::basic_string<CharT,Traits,Allocator>::length
- std::basic_string<CharT,Traits,Allocator>::shrink_to_fit (3) - std::basic_string<CharT,Traits,Allocator>::shrink_to_fit
- std::basic_string<CharT,Traits,Allocator>::starts_with (3) - std::basic_string<CharT,Traits,Allocator>::starts_with
- std::basic_string<CharT,Traits,Allocator>::substr (3) - std::basic_string<CharT,Traits,Allocator>::substr
- std::basic_string<CharT,Traits,Allocator>::swap (3) - std::basic_string<CharT,Traits,Allocator>::swap
- std::basic_string<CharT,Traits,Allocator>::append (3) - std::basic_string<CharT,Traits,Allocator>::append
- std::basic_string<CharT,Traits,Allocator>::assign (3) - std::basic_string<CharT,Traits,Allocator>::assign
- std::basic_string<CharT,Traits,Allocator>::at (3) - std::basic_string<CharT,Traits,Allocator>::at
- std::basic_string<CharT,Traits,Allocator>::back (3) - std::basic_string<CharT,Traits,Allocator>::back
- std::basic_string<CharT,Traits,Allocator>::basic_string (3) - std::basic_string<CharT,Traits,Allocator>::basic_string
- std::basic_string<CharT,Traits,Allocator>::begin, (3) - std::basic_string<CharT,Traits,Allocator>::begin,
- std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin (3) - std::basic_string<CharT,Traits,Allocator>::begin,std::basic_string<CharT,Traits,Allocator>::cbegin
- std::basic_string<CharT,Traits,Allocator>::c_str (3) - std::basic_string<CharT,Traits,Allocator>::c_str
- std::basic_string<CharT,Traits,Allocator>::capacity (3) - std::basic_string<CharT,Traits,Allocator>::capacity
- std::basic_string<CharT,Traits,Allocator>::clear (3) - std::basic_string<CharT,Traits,Allocator>::clear
- std::basic_string<CharT,Traits,Allocator>::compare (3) - std::basic_string<CharT,Traits,Allocator>::compare
- std::basic_string<CharT,Traits,Allocator>::copy (3) - std::basic_string<CharT,Traits,Allocator>::copy
- std::basic_string<CharT,Traits,Allocator>::data (3) - std::basic_string<CharT,Traits,Allocator>::data
- std::basic_string<CharT,Traits,Allocator>::empty (3) - std::basic_string<CharT,Traits,Allocator>::empty
- std::basic_string<CharT,Traits,Allocator>::end, (3) - std::basic_string<CharT,Traits,Allocator>::end,
- std::basic_string<CharT,Traits,Allocator>::end,std::basic_string<CharT,Traits,Allocator>::cend (3) - std::basic_string<CharT,Traits,Allocator>::end,std::basic_string<CharT,Traits,Allocator>::cend
- std::basic_string<CharT,Traits,Allocator>::ends_with (3) - std::basic_string<CharT,Traits,Allocator>::ends_with
- std::basic_string<CharT,Traits,Allocator>::erase (3) - std::basic_string<CharT,Traits,Allocator>::erase
- std::basic_string<CharT,Traits,Allocator>::find (3) - std::basic_string<CharT,Traits,Allocator>::find
- std::basic_string<CharT,Traits,Allocator>::find_first_not_of (3) - std::basic_string<CharT,Traits,Allocator>::find_first_not_of
- std::basic_string<CharT,Traits,Allocator>::find_first_of (3) - std::basic_string<CharT,Traits,Allocator>::find_first_of
- std::basic_string<CharT,Traits,Allocator>::find_last_not_of (3) - std::basic_string<CharT,Traits,Allocator>::find_last_not_of
- std::basic_string<CharT,Traits,Allocator>::find_last_of (3) - std::basic_string<CharT,Traits,Allocator>::find_last_of
- std::basic_string<CharT,Traits,Allocator>::front (3) - std::basic_string<CharT,Traits,Allocator>::front
- std::basic_string<CharT,Traits,Allocator>::get_allocator (3) - std::basic_string<CharT,Traits,Allocator>::get_allocator
- std::basic_string<CharT,Traits,Allocator>::insert (3) - std::basic_string<CharT,Traits,Allocator>::insert
- std::basic_string<CharT,Traits,Allocator>::max_size (3) - std::basic_string<CharT,Traits,Allocator>::max_size
- std::basic_string<CharT,Traits,Allocator>::npos (3) - std::basic_string<CharT,Traits,Allocator>::npos
- std::basic_string<CharT,Traits,Allocator>::operator+= (3) - std::basic_string<CharT,Traits,Allocator>::operator+=
- std::basic_string<CharT,Traits,Allocator>::operator= (3) - std::basic_string<CharT,Traits,Allocator>::operator=
- std::basic_string<CharT,Traits,Allocator>::operator[] (3) - std::basic_string<CharT,Traits,Allocator>::operator[]
- std::basic_string<CharT,Traits,Allocator>::operatorbasic_string_view (3) - std::basic_string<CharT,Traits,Allocator>::operatorbasic_string_view
- std::basic_string<CharT,Traits,Allocator>::pop_back (3) - std::basic_string<CharT,Traits,Allocator>::pop_back
- std::basic_string<CharT,Traits,Allocator>::push_back (3) - std::basic_string<CharT,Traits,Allocator>::push_back
- std::basic_string<CharT,Traits,Allocator>::rbegin, (3) - std::basic_string<CharT,Traits,Allocator>::rbegin,
- std::basic_string<CharT,Traits,Allocator>::rbegin,std::basic_string<CharT,Traits,Allocator>::crbegin (3) - std::basic_string<CharT,Traits,Allocator>::rbegin,std::basic_string<CharT,Traits,Allocator>::crbegin
- std::basic_string<CharT,Traits,Allocator>::rend, (3) - std::basic_string<CharT,Traits,Allocator>::rend,
- std::basic_string<CharT,Traits,Allocator>::rend,std::basic_string<CharT,Traits,Allocator>::crend (3) - std::basic_string<CharT,Traits,Allocator>::rend,std::basic_string<CharT,Traits,Allocator>::crend
- std::basic_string<CharT,Traits,Allocator>::replace (3) - std::basic_string<CharT,Traits,Allocator>::replace
- std::basic_string<CharT,Traits,Allocator>::reserve (3) - std::basic_string<CharT,Traits,Allocator>::reserve
- std::basic_string<CharT,Traits,Allocator>::resize (3) - std::basic_string<CharT,Traits,Allocator>::resize
- std::basic_string<CharT,Traits,Allocator>::rfind (3) - std::basic_string<CharT,Traits,Allocator>::rfind