A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/string::length below:

public member function

<string>

std::string::length
size_t length() const noexcept;

Return length of string

Returns the length of the string, in terms of bytes.

This is the number of actual bytes that conform the contents of the string, which is not necessarily equal to its storage capacity.

Note that string objects handle bytes without knowledge of the encoding that may eventually be used to encode the characters it contains. Therefore, the value returned may not correspond to the actual number of encoded characters in sequences of multi-byte or variable-length characters (such as UTF-8).

Both string::size and string::length are synonyms and return the exact same value.



Parameters none

Return Value The number of bytes in the string.

size_t is an unsigned integral type (the same as member type string::size_type).



Example
1
2
3
4
5
6
7
8
9
10
// string::length
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  std::cout << "The size of str is " << str.length() << " bytes.\n";
  return 0;
}

Output:
The size of str is 11 bytes


Complexity
Iterator validity No changes.

Data races The object is accessed.

Exception safetyNo-throw guarantee: this member function never throws exceptions.

See also
string::size
Return length of string (public member function)
string::resize
Resize string (public member function)
string::max_size
Return maximum size of string (public member function)
string::capacity
Return size of allocated storage (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4