String Size Function - C++ Programming Tutorial
C++ Course / Strings / String Size Function

String Size Function

BLUF: Mastering String Size Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: String Size Function

C++ is renowned for its efficiency. Learn how String Size Function enables low-level control and high-performance computing in the tutorial below.

C++ String size

This function is employed to retrieve the byte length of a string. It specifies the precise count of bytes that represent the string's content, which may differ from its capacity.

Syntax

To determine the length of a string object named 'str', you can use the following syntax:

Example

str.size()

Parameters

This function does not contain any parameter.

Return Value

This function calculates and returns the total count of characters existing within the string entity.

Example 1

Example

#include<iostream>
using namespace std;
int main()
{
string str ="Welcome to the javacpptutorial tutorial";
int size = str.size();
cout << "length of the string is :" <<size; 
return 0;
}

Output:

Output

length of the string is : 34

In this instance, the variable str represents a string object with the content "Welcome to the javacpptutorial tutorial". The size function is employed to determine the length of the string.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience