public member function

std::string::length

<string>
size_t length() const;
Return length of string
Returns a count of the number of characters in the string.

string::length is an alias of string::size, returning both the exact same value.

Parameters

none

Return Value

The number of characters that conform the string's content.

size_t is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
// string::length
#include <iostream>
#include <string>
using namespace std;

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


Output:
The length of str is 11 characters.

Basic template member declaration

( basic_string<charT,traits,Allocator> )
1
2
typedef typename Allocator::size_type size_type;
size_type length() const;


See also