public member function
<string>
Clear string
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
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// string::clear
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str;
char c;
cout << "Please type some lines of text. Enter a period to finish:\n";
do {
c=cin.get();
str += c;
if (c=='\n')
{
cout << str;
str.clear();
}
} while (c!='.');
return 0;
}
|
This program repeats every line introduced by the user until a period character (
'.') is introduced. Every newline character (
'\n') triggers the repetition of the line and the clearing of the current string content.
Basic template member declaration
( basic_string<charT,traits,Allocator> )
See also
- string::erase
- Erase characters from string (public member function)
- string::resize
- Resize string (public member function)
- string::empty
- Test if string is empty (public member function)