string capacity() in C++

capacity(): It returns the total number of characters that the string can hold before needing to 

allocate more memory.

Parameter: No parameters are required for this function.

Syntax:

str.capacity()

For Example:

str = "abc"

str.capacity() => It returns maximum capacity (i.e 15)

Approach

C++

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

int main()
{
    string str = "abc";
    cout << str.capacity() << "\n";
    
    return 0;
}


No comments:

Post a Comment