GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_string::size,(3) C++ Standard Libary std::basic_string::size,(3)

std::basic_string::size, - std::basic_string::size,


size_type size() const; (until C++11)
size_type size() const noexcept; (since C++11)
(until C++20)
constexpr size_type size() const noexcept; (since C++20)
size_type length() const; (until C++11)
size_type length() const noexcept; (since C++11)
(until C++20)
constexpr size_type length() const noexcept; (since C++20)


Returns the number of CharT elements in the string, i.e. std::distance(begin(),
end()).


(none)


The number of CharT elements in the string.


Unspecified (until C++11)
Constant (since C++11)


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.

// 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("ハロー・ワールド"); // 8 code points
assert(24 == c.size()); // 24 code units in UTF-8


#if __cplusplus >= 202002
std::u8string d(u8"ハロー・ワールド"); // 8 code points
assert(24 == d.size()); // 24 code units in UTF-8
#endif
}


empty checks whether the string is empty
(public member function)
max_size returns the maximum number of characters
(public member function)
size returns the number of characters
length (public member function of std::basic_string_view<CharT,Traits>)
(C++17)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.