C++ string clear() Function
Example
Remove all characters from a string:
string txt = "Hello World!";
txt.clear();
cout << "Length: " << txt.length();
Definition and Usage
The clear() function removes all characters from a string. After this, the string is empty, and its length is 0.
The clear function is defined in the <string> header file.
Syntax
string.clear();
Parameter Values
None.
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about strings in our String Tutorial.