You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 C++ String clear on Wed Jan 12, 2011 1:59 am

des

avatar
Achiever
Loading
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;
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> )
void clear ( );

2 Re: C++ String clear on Wed Jan 12, 2011 3:24 am

DJ Fresh

avatar
Master
Loading
Thanks bro.

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum