C++ String Library - size


Advertisements

Description

It returns the length of the string, in terms of bytes.

Declaration

Following is the declaration for std::string::size.

size_t size() const;

C++11

 size_t size() const noexcept;

Parameters

none

Return Value

It returns the length of the string, in terms of bytes.

Exceptions

Never throw any exceptions.

Example

In below example for std::string::size.

#include <iostream>
#include <string>

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

The sample output should be like this −

The size of str is 22 bytes.
string.htm
Advertisements