cplusplus.com
C++ : Reference : Strings library : string : length
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Strings library
char_traits
classes:
string
global functions:
getline
operator+
operator<<
operator>>
comparison operators
swap
string
string::string
member constants:
string::npos
member functions:
string::append
string::assign
string::at
string::begin
string::capacity
string::clear
string::compare
string::copy
string::c_str
string::data
string::empty
string::end
string::erase
string::find
string::find_first_not_of
string::find_first_of
string::find_last_not_of
string::find_last_of
string::get_allocator
string::insert
string::length
string::max_size
string::operator+=
string::operator=
string::operator[]
string::push_back
string::rbegin
string::rend
string::replace
string::reserve
string::resize
string::rfind
string::size
string::substr
string::swap


string::length

public member function
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