cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : size
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::size public member function
size_t size() 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

// string::size
#include <iostream>
#include <string>
using namespace std;

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

Output:

The size of str is 11 characters.

Basic template member declaration

( basic_string<charT,traits,Allocator> )
typedef typename Allocator::size_type size_type;
size_type size() const;

See also

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)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us