A RetroSearch Logo

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

Search Query:

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

public member function

<string>

std::basic_string::length
size_type length() const;
size_type length() const noexcept;

Return length of string

Returns the length of the string, in terms of number of characters.

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

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



Parameters none

Return Value The number of characters in the string.

Member type size_type is an unsigned integral 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() << " characters.\n";
  return 0;
}

Output:
The size of str is 11 characters


Complexity
Iterator validity No changes.

Data races The object is accessed.

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

See also
basic_string::size
Return size (public member function)
basic_string::resize
Resize string (public member function)
basic_string::max_size
Return maximum size (public member function)
basic_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