VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdstringclear-in-cpp/

⇱ std::string::clear in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::string::clear in C++

Last Updated : 23 Jul, 2025
The string content is set to an empty string, erasing any previous content and thus leaving its size at 0 characters. Parameters: none Return Value: none
void string ::clear ()
- Removes all characters (makes string empty)
- Doesn't throw any error
- Receives no parameters and returns nothing
Output:
Before clear : Hello World!
After clear : 
Related Article: std::string::erase If you like GeeksforGeeks (We know you do!) and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org.
Comment
Article Tags: