string clear() in C++

clear(): Erases the string, making it empty. 

This is available in the below file

File: basic_string.h

Parameter: No parameters are required for this function.

Syntax:

str.clear()

For Example:

str = "abc"

str.clear() = > It empty the string. So size of string becomes 0 or we say str ="".

Approach

C++

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

int main()
{
    string str = "abc";

    //clear the string
    str.clear();

    cout << str.size() << "\n";
    
    return 0;
}


No comments:

Post a Comment