1 C++ String clear Wed Jan 12, 2011 1:59 am
des
Achiever
void clear();
What does it do? The string content is set to an empty string, erasing any previous content and thus leaving its size at 0 characters.
Quick example:
Basic template member declaration
( basic_string<charT,traits,Allocator> )
void clear ( );
What does it do? The string content is set to an empty string, erasing any previous content and thus leaving its size at 0 characters.
Quick example:
- Code:
// 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;
Basic template member declaration
( basic_string<charT,traits,Allocator> )
void clear ( );