string size() in C++

size(): This function returns the number of characters in the string,

not including any null-termination.

This function is available in the below file

File: basic_string.h

Parameters: No parameters are required for this function.

Syntax:

str.size()

For Example:

str = "abc"

str.size() => It returns length of string (i.e 3)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{

    string str = "abc";

    cout << str.size() << "\n";

    return 0;
}


No comments:

Post a Comment