C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ String clear()This function removes the elements, becomes an empty string. SyntaxConsider a string str. Syntax would be: str.clear(); ParameterThis function does not contain any parameter. Return valueThis function does not return any value. ExampleLet's see a simple example of clear() function: #include<iostream> using namespace std; int main() { stringstr; cout<<?Enter some lines about javaTpoint and write dot character to finish the sentence?<<?\n?; cout<<?If you want to clear the text, press d?<<?\n?; do{ charch =cin.get(); str+=ch; if(ch==?d?) str.clear(); }while(ch!=?.?); return 0; } Output: Enter some lines about javaTpoint and write dot character to finish the sentence If you want to clear the text, press d This example shows how clear() function works.
Next TopicC++ Strings
|